【问题标题】:Action delegate in .NET2 - Using the generic type 'System.Action<T>' requires '1' type arguments.NET2 中的动作委托 - 使用泛型类型“System.Action<T>”需要“1”类型参数
【发布时间】:2011-11-25 00:01:16
【问题描述】:

我正在将工作代码从 .NET4 移植到 .NET2(WinCE 设备)。

.NET2中不允许使用不带参数不返回值的Action

下面第 5 行的编译错误:使用泛型类型 'System.Action' 需要 '1' 类型参数

解决方法的想法?

//first state is the default for the system
    public enum States { EnterVoucherCode, EnterTotalSale, ProcessVoucher };
    public enum Events { PressNext, PressRedeem, ProcessSuccess, ProcessFail, PressBackToVoucherCode };

    public States State { get; set; }

    private Action[,] fsm; //Fails to compile here

    public FiniteStateMachine()
    {
        //array of action delegates
        fsm = new Action[3, 5] { 
        //PressNext,     PressRedeem,            ProcessSuccess,      ProcessFail,      PressBackToVoucherCode

【问题讨论】:

    标签: c# delegates


    【解决方案1】:

    确实,非泛型 Action 已添加到 .NET 3.5 中。

    然而,Action 只是一个普通的委托类型,所以你可以简单地滚动你自己的类型,如下所示:

    public delegate void Action();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      相关资源
      最近更新 更多