当前位置:网站首页>关于c#委托、事件相关问题
关于c#委托、事件相关问题
2022-06-13 07:02:00 【万年之光】
1.委托的实质
大家应该都知道函数的调用都是先寻找函数的首地址,然后在去调用,而委托的本质是记录函数的首地址,就和调用函数的本质一样。
2.委托的初始化与自定义类型初始化区别
1.委托
委托能够在赋值为NULL的情况下,在去赋值函数名,可以正常调用,不需要new。
2.自定义类型(引用类型)
一定要new才能给其中的成员元素赋值,为什么呢?例如:
class Test
{
public int a;
}
Test s=null;
s.a=100;
Console.WriteLine(s.a);
会直接报错,因为其没有初始化,没有为改变量申请内存空间,只有变量名有内容空间。
原因:委托可以不用new的原因就是因为变量名可以直接赋予函数的首地址,可以去直接访问。
事件
1.事件只能在类内定义,类内去调用,因为其真实的写法是私有的,不能直接去调用
边栏推荐
- Gold jewelry enterprise operation mode, beautiful tiantians business solution
- 2022 - 06 - 12: dans un échiquier carré n * N, il y a n * n pièces, donc chaque pièce peut avoir exactement une pièce. Mais maintenant quelques pièces sont rassemblées sur une grille, par exemple: 2 0
- 基于ESP32CAM实现WebSocket服务器实时点灯
- 不间断管理设计
- 号称下一代监控系统 来看看它有多牛逼
- Is it safe to open an account online in Hangzhou?
- What does my financial product mean in clearing?
- RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
- 尝试使用RenderDoc查看UE的Shader代码
- Soup side (8)
猜你喜欢
对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
How to use Wangyou DFM software for cold plate analysis
An article allows you to quickly understand the fission growth password of social e-commerce user marketing and avoid stepping on the pit
SDN basic overview
Jinglianwen Technology: current situation and solutions of data acquisition and labeling industry
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
基于SSM实现水果商城批发平台
Jinglianwen Technology: current situation and solutions of data annotation industry
Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge
如何从头自己制作开发板?图文并茂,一步步操作给你看。
随机推荐
Comment utiliser le logiciel wangyou DFM pour l'analyse des plaques froides
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
Monotone stack top31 of interview must brush algorithm top101
如何从头自己制作开发板?图文并茂,一步步操作给你看。
不间断管理设计
Jinglianwen technology provides voice data acquisition and labeling services
[weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background
如何使用望友DFM软件进行冷板分析
Byte (nine)
JS case Xiaomi second kill countdown New Year Countdown
Tikv key performance parameters and optimization
JS method of extracting numbers from strings
How to quickly support the team leader to attract new fission users in the business marketing mode of group rebate?
基于ESP32CAM实现WebSocket服务器实时点灯
[cloud native | kubernetes] kubernetes configuration
SDN basic overview
Unable to find method 'org gradle. api. artifacts. result. ComponentSelectionReason. getDesc
The new retail market has set off blind box e-commerce. Can the new blind box marketing model bring dividends to businesses?
The biggest highlight of wwdc2022: metalfx
Select all select none JS code implementation