-->

Why I cannot use as entry point in C# app a generi

2019-09-21 11:07发布

问题:

In C# the method Main must be in a nongeneric type in order to be selected as entry point. Why is that?

I'm a little bit confused about that because that is possible in Java (the function main() can be in a generic class).

namespace ConsoleApplication
{
    class Program<T> //incorrect
    {
        static void Main(string[] args)
        {
        }
    }
}

回答1:

The Main method serves as a fixed interface to the operating system, which itself has no mechanism to select and specify a type to be given as a parameter.