Why can a .NET delegate not be declared static?

后端 未结 6 2191
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 19:42

When I try to compile the following:

public static delegate void MoveDelegate (Actor sender, MoveDirection args);

I receive, as an error: \

6条回答
  •  遥遥无期
    2020-12-08 20:18

    public static delegate void MoveDelegate (Actor sender, MoveDirection args);
    

    Let me tell you what happened when you declared a delegate

    The compiler creates a class, in this case named MoveDelegate, and extends it with System.MulticastDelegate.

    Since you can not extend any non static type by static type.

    So this is the reason why the compiler does not allow static delegate declaration. But still you can have static delegate reference.

提交回复
热议问题