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

后端 未结 3 551
旧巷少年郎
旧巷少年郎 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:54

    This probably is a problem with type inferance, apperently the compiler infers a as an Action instead of Action (it might think a is ActionSurrogate, which would fit the Action> signature). Try specifying the type of a explicitly:

        ActionSurrogate b = (Action a) =>
                            {
                                a();
                            };
    

    If this is not the case - might check around your project for any self defined Action delegates taking one parameter.

提交回复
热议问题