当前位置:网站首页>关于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.事件只能在类内定义,类内去调用,因为其真实的写法是私有的,不能直接去调用
边栏推荐
- [cloud native | kubernetes] kubernetes configuration
- Tidb implementation plan -- III
- [turn to] FPGA interview questions
- 【腾讯阿里最全面试题集锦】(四面:3轮技术+1轮HR)
- Computer network interview questions
- FSM state machine
- When the concept of industrial Internet just appeared, people only regarded it as a method to obtain b-end traffic
- Ml: introduction to stability analysis of machine learning model and detailed introduction to common solutions
- What is the essence of social e-commerce disruption? How can businesses get more traffic?
- 基于FPGA的ds18b20温度传感器使用
猜你喜欢
The innovative public platoon mode team invites users to split, beautiful every second, and links the 2+1 new business model
对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
[cloud native | kubernetes] kubernetes configuration
Computer network interview questions
2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
What is the new business model of Taishan crowdfunding in 2022?
Continuous management design
WWDC2022最大的亮点: MetalFX
Comment utiliser le logiciel wangyou DFM pour l'analyse des plaques froides
线程池中的 工作线程如何被回收
随机推荐
Will the chain 2+1 model be a new business outlet and a popular Internet e-commerce market?
First day of learning MySQL Basics
如何使用望友DFM软件进行冷板分析
汇编语言基础:寄存器和寻址方式
Normalizing y-axis in histograms in R ggplot to proportion
基于FPGA的ds18b20温度传感器使用
上位机开发(固件下载软件之架构设计)
对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
Implementation of fruit mall wholesale platform based on SSM
Br backup test
Unable to find method 'org gradle. api. artifacts. result. ComponentSelectionReason. getDesc
An article allows you to quickly understand the fission growth password of social e-commerce user marketing and avoid stepping on the pit
在 localStorage 中上传和检索存储图像
Is it safe for Hangzhou Securities to open an account?
Priority analysis of list variables in ansible playbook and how to separate and summarize list variables
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
RT-Thread 模拟器 simulator LVGL控件:slider 控件
Why is the blind box e-commerce mode so popular?
Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders
[Tencent Alibaba's most comprehensive collection of test questions] (four sides: three rounds of technology +1 round of HR)