当前位置:网站首页>A simple example of delegate usage
A simple example of delegate usage
2022-07-07 10:48:00 【HCC2017】
public delegate void LogDelegate(string log); // Definition The delegate name is LogDelegate, With a string Parametric Delegate type
public static LogDelegate LogEvent; // Declare the delegate object , The delegate instance is LogEvent
public static void OnLogEvent(string log)
{
if (LogEvent != null)
{
LogEvent(log);
}
}
}
/// <summary>
/// Add call event , The delegate
/// </summary>
class TextDelegate : MonoBehaviour
{
void Start()
{
TextDelegate2.LogEvent += Cat;
TextDelegate2.LogEvent += Dog;
TextDelegate2.OnLogEvent(" Feed the small animals ");// Send callback information to the function
}
void Cat(string log)
{
Debug.Log(" cat :" + log);
}
void Dog(string log)
{
Debug.Log(" Wang Wang Wang :" + log);
}
}
边栏推荐
- CAS mechanism
- What are the contents of the intermediate soft test, the software designer test, and the test outline?
- The width of table is 4PX larger than that of tbody
- 如何顺利通过下半年的高级系统架构设计师?
- Mendeley -- a free document management tool that automatically inserts references into papers
- Prototype and prototype chain
- Mendeley--免费的文献管理工具,给论文自动插入参考文献
- Gym installation pit records
- CSAPP Bomb Lab 解析
- [STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
猜你喜欢
随机推荐
July 10, 2022 "five heart public welfare" activity notice + registration entry (two-dimensional code)
IIC基本知识
Leetcode-304: two dimensional area and retrieval - matrix immutable
小程序跳转H5,配置业务域名经验教程
[detailed explanation of Huawei machine test] tall and short people queue up
Long list performance optimization scheme memo
【亲测可行】error while loading shared libraries的解决方案
JS实现链式调用
如何顺利通过下半年的高级系统架构设计师?
Multithreaded asynchronous orchestration
OpenGL glLightfv 函数的应用以及光源的相关知识
What does intermediate software evaluator test
[système recommandé 01] rechub
The gun startles the dragon, and the crowd "locks" Zhou Zhi
Unable to open kernel device '\.\vmcidev\vmx': operation completed successfully. Reboot after installing vmware workstation? Module "devicepoweron" failed to start. Failed to start the virtual machine
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
The width of table is 4PX larger than that of tbody
The mobile terminal automatically adjusts the page content and font size by setting rem
Deep understanding of Apache Hudi asynchronous indexing mechanism
一些线上学术报告网站与机器学习视频