Search code examples
c#delegatesprogram-entry-point

Delegate with a main method


I can't access my delegate in the main method. I think it has something to do with the static main. But I can't make my delegate static.

public delegate double Calculation(double number1, double number2);

static void Main(string[] args)
{
}

Solution

  • The delegate type you declared can certainly be used from Main:

    public delegate double Calculation(double number1, double number2);
    
    public static void Main(string[] args)
    {
        Calculation x = null;
    }
    

    Demo: http://rextester.com/OOXL56068

    Most likely you are confused about using delegates in general, and the static method Main has nothing to do with your problem whatsoever.