Why can a .NET delegate not be declared static?

后端 未结 6 2175
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  -上瘾入骨i
    2020-12-08 20:23

    You are declaring a delegate type. It doesn't make any sense to declare it as static. You could declare an instance of your delegate type as static, though.

    public delegate void BoringDelegate();
    
    
    internal class Bar {
        public static BoringDelegate NoOp;
        static Bar() {
            NoOp = () => { };
        }
    }
    

提交回复
热议问题