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

2019-09-21 10:27发布

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条回答
唯我独甜
2楼-- · 2019-09-21 11:11

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.

查看更多
登录 后发表回答