Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

delegates

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
like image 238
Dave Mateer Avatar asked Nov 25 '11 00:11

Dave Mateer


1 Answers

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();
like image 91
Etienne de Martel Avatar answered Oct 05 '22 23:10

Etienne de Martel