'Delegate 'System.Action' does not take 0 arguments.' Is this a C# compiler bug (lambdas + two projects)?

后端 未结 3 546
旧巷少年郎
旧巷少年郎 2020-11-30 05:30

Consider the code below. Looks like perfectly valid C# code right?

//Project B
using System;
public delegate void ActionSurrogate(Action addEvent);
//public          


        
3条回答
  •  庸人自扰
    2020-11-30 05:56

        public static void ThisWontCompile()
            {
                ActionSurrogate b = (Action a) =>
                {
                    a();
                };
    
    
            }
    

    This will compile. Some glitch with the compiler its unable to find the Action delegate without parameters. That's why you are getting the error.

    public delegate void Action();
    public delegate void Action();
    public delegate void Action();
    public delegate void Action();
    public delegate void Action();
    

提交回复
热议问题