.NET2中的操作委托 - 使用泛型类型'System.Action <t>'需要'1'类型参数</t>

时间:2011-11-25 00:01:17

标签: c# delegates

我正在将工作代码从.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

1 个答案:

答案 0 :(得分:11)

实际上,在.NET 3.5中添加了非通用Action

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

public delegate void Action();
相关问题