当前位置:网站首页>关于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.事件只能在类内定义,类内去调用,因为其真实的写法是私有的,不能直接去调用
边栏推荐
- 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
- The innovative public platoon mode team invites users to split, beautiful every second, and links the 2+1 new business model
- Upper computer development (code debugging of firmware download software)
- How to quickly support the team leader to attract new fission users in the business marketing mode of group rebate?
- 10 Honest Facts I Want To Share With All Junior Developers
- NFV基本概述
- Can flush open a stock account? Is it safe?
- Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?
- Why is the blind box e-commerce mode so popular?
- 测试开发程序员,你还在迷茫吗?不能把自己定义为码农......
猜你喜欢

Intelligent entertainment has developed steadily, and jinglianwen technology provides data collection and labeling services

What is the essence of social e-commerce disruption? How can businesses get more traffic?

景联文科技:数据采集标注行业现状及解决方案

ML之FE:Vintage曲线/Vintage分析的简介、计算逻辑、案例应用之详细攻略

Gold jewelry enterprise operation mode, beautiful tiantians business solution

Learning notes of MySQL series by database and table

Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders

How to seize the bonus of social e-commerce through brand play to achieve growth and profit?

Eureka server multi node deployment

Application of DS18B20 temperature sensor based on FPGA
随机推荐
测试开发程序员,你还在迷茫吗?不能把自己定义为码农......
FSM状态机
Why does TCP establish three handshakes and four waves
上位机开发(固件下载软件之软件测试)
1154. day of the year
RT-Thread 模拟器 simulator LVGL控件:button 按钮样式
【转】FPGA面试题
Learning notes of MySQL series by database and table
Detailed description of drawing ridge plot, overlapping densities of overlapping kernel density estimation curve, facetgrid object and function sns Kdeplot, function facetgrid map
How to quickly support the team leader to attract new fission users in the business marketing mode of group rebate?
How to seize the bonus of social e-commerce through brand play to achieve growth and profit?
Br tool backup recovery
如何使用望友DFM软件进行冷板分析
Periodontitis investigation (ongoing)
Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge
通过函数seaborn.cubehelix_palette生成顺序调色板
RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
髋关节MR详细图谱(转载)
Try to use renderdoc to view the shader code of UE
Xiaomi's one-sided interview questions (self sorting answers)