当前位置:网站首页>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);
}
}
边栏推荐
- Online hard core tools
- P1031 [NOIP2002 提高组] 均分纸牌
- Using U2 net deep network to realize -- certificate photo generation program
- Those confusing concepts (3): function and class
- 宁愿把简单的问题说一百遍,也不把复杂的问题做一遍
- [牛客网刷题 Day6] JZ27 二叉树的镜像
- Some online academic report websites and machine learning videos
- Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
- [牛客网刷题 Day5] JZ77 按之字形顺序打印二叉树
- Trajectory planning for multi robot systems: methods and Applications Overview reading notes
猜你喜欢
P1223 queuing for water /1319: [example 6.1] queuing for water
CSAPP bomb lab parsing
Trajectory planning for multi robot systems: methods and Applications Overview reading notes
Leetcode-304: two dimensional area and retrieval - matrix immutable
Mendeley -- a free document management tool that automatically inserts references into papers
Application of OpenGL gllightfv function and related knowledge of light source
1324: [example 6.6] integer interval
Prototype and prototype chain
Online hard core tools
【实战】霸榜各大医学分割挑战赛的Transformer架构--nnFormer
随机推荐
Some online academic report websites and machine learning videos
优雅的 Controller 层代码
[OneNote] can't connect to the network and can't sync the problem
[daiy5] jz77 print binary tree in zigzag order
2022年上半年5月网络工程师试题及答案
“梦想杯”2017 年江苏省信息与未来小学生夏令营 IT 小能手 PK 之程序设计试题
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
Mendeley -- a free document management tool that automatically inserts references into papers
CAS mechanism
How to prepare for the advanced soft test (network planning designer)?
P2788 math 1 - addition and subtraction
MONAI版本更新到 0.9 啦,看看有什么新功能
深入理解Apache Hudi异步索引机制
Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
P1223 queuing for water /1319: [example 6.1] queuing for water
PHP \ newline cannot be output
[dai6] mirror image of JZ27 binary tree
原型与原型链
[homework] 2022.7.6 write your own cal function
JS实现链式调用