当前位置:网站首页>C event usage case subscription event+=
C event usage case subscription event+=
2022-07-27 07:50:00 【Jinan medical applet champion】
C# Event usage
using System;
namespace WeiTuo
{
class Program
{
// SayUpdate Type of event . The statement 1 Events .
public static event SayUpdate SayHelloEvent;
// Delegate with one parameter And no return value of the delegate
public delegate void SayUpdate(string name);
static void Main(string[] args)
{
// Statement of delegation How to use delegation Interpretation of entrustment Pass the method as a variable , And execute in the form of method .
//
SayUpdate dlg = SayHi;
dlg += SayBye;
dlg -= SayBye;
//dlg(" voice , How do you do ");
// Anonymous functions
// How to use events += -= 1 use += Subscription events Incidents 2 A way , One += One -= Method .
// register Subscription events .
SayHelloEvent += Program_SayHelloEvent;
// Judge whether the event exists . Not empty .
if(SayHelloEvent != null)
{
SayHelloEvent(" Lao Wang "); // Call event
}
Console.ReadLine();
}
private static void Program_SayHelloEvent(string name)
{
//throw new NotImplementedException();
Console.WriteLine($"{name}, I'm an event !");
}
public static void SayHi(string name)
{
Console.WriteLine($"{ name}, How do you do Speech technology ");
}
public static void SayBye(string name)
{
Console.WriteLine($"{ name}, bye ");
}
}
}
effect

边栏推荐
- 企业架构驱动的数字化转型!
- MySQL table name area in Linux is not case sensitive
- 【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement
- Systematic explanation of unit testing: mockito
- 擎创科技加入龙蜥社区,共建智能运维平台新生态
- 孙子出题难,儿子监考严。老子不会做,还我上学钱
- Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
- linux能不能安装sqlserver
- Convert objects to key value pairs
- ADC噪声全面分析 -02- ADC 噪声测量方法和相关参数
猜你喜欢
为啥国内大厂都把云计算当成香饽饽,这个万亿市场你真的了解吗

Zero training platform course-1. SQL injection Foundation

STM32_ Find the cause of entering hardfault_ Handler's function

Promise详解

【QT】capture. Obj:-1: error: lnk2019: unresolved external symbols__ imp_ Htons (solution)

linux能不能安装sqlserver

自动化测试的使用场景

C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)

Hu related configuration

抽象工厂模式
随机推荐
Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money
Shell Scripts相关
Demo submit a program and obtain ALV data of the program
Shell functions and arrays exercises
Lua有状态迭代器
The first open source MySQL native HTAP database in China will be released soon! Look at the three highlights first, limited to the surrounding areas, waiting for you~
杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?
[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement
国内首款开源MySQL原生HTAP数据库即将发布!三大亮点抢先看,限量周边等你来~
LeetCode56. 合并区间
Abstract factory pattern
【小程序】uniapp发行微信小程序上传失败Error: Error: {'errCode':-10008,'errMsg':'invalid ip...
帮个忙呗~不关注不登录,不到一分钟的一个问卷
Enhancement: BTE process introduction
glGetUniformLocation,glUniform4f
[resolved] the new version of pychart (2022) connects to the server to upload files and reports an error of "command Rsync is not found in path", and the files cannot be synchronized
Gossip: is rotting meat in the pot to protect students' rights and interests?
正则 和 sed 练习
C语言:随机生成数+插入排序
Leetcode54. 螺旋矩阵