C#,事件和没有关键字事件的委托的区别,我看不懂[重复]

C#, difference between event and delegate without keyword event, I can't understand [duplicate]

提问人:Anonymous 提问时间:12/20/2022 最后编辑:Hossein SabzianiAnonymous 更新时间:1/5/2023 访问量:47

问:

C#. 如果你在技术面试中被问到这个问题,你会如何回答?

请介绍一下这些情况的区别:

1)

public class SampleClass
{
    public System.Action a;
}
public class SampleClass
{
    public event System.Action a;
}
C# NET . net-core 事件 委托

评论


答:

1赞 Hossein Sabziani 12/20/2022 #1

C# 中的事件是类用来 的一种机制。它们是一种专门的委托类型,我们用它来通知其他类,当它们侦听的事情发生时。事件是许多应用程序的重要组成部分,也是解耦和创建灵活且可扩展的应用程序的完美方式。send notifications or messages to other classes

委托 .如果我们调用委托,则会调用引用的方法。委托具有调用具有特定签名和返回类型的方法或方法组所需的所有信息。我们可以将委托作为参数传递给其他方法,也可以将其存储在结构或类中。is a reference to a method