Action delegate in .NET2 - Using the generic type 'System.Action<T>' requires '1' type arguments

被刻印的时光 ゝ 提交于 2019-12-19 19:51:59

问题


I'm porting working code from .NET4 to .NET2 (a WinCE device).

The usage of Action taking no arguments and returning no value isn't allowed in .NET2

compile error on line 5 below: Using the generic type 'System.Action' requires '1' type arguments

Workaround thoughts?

//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:


Indeed, the non-generic Action was added in .NET 3.5.

However, Action is just an ordinary delegate type, so you could simply roll your own, like so:

public delegate void Action();


来源:https://stackoverflow.com/questions/8263626/action-delegate-in-net2-using-the-generic-type-system-actiont-requires-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!