C# - Anonymous delegate

前端 未结 7 1806
有刺的猬
有刺的猬 2021-02-07 08:00

Like Anonymous Methods ,the delegates i am declaring down using \"delegate\" keyword are anonymous delegates?

namespace Test
{
    public delegate void MyDelegat         


        
7条回答
  •  一生所求
    2021-02-07 08:16

    Your delegate is not anonymous. It's called MyDelegate. Delegate in CLR is a class that derives from System.MulticastDelegate and in your case it's called MyDelegate. You cannot directly derive from MulticastDelegate, C# compiler will stop you.

    In your code when you assign delegates to del, the type/name of the delegate is inferred by compiler because you declared del as event of type MyDelegate.

提交回复
热议问题