Why I cannot use as entry point in C# app a generic type?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 09:36:10

问题


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.



来源:https://stackoverflow.com/questions/28045923/why-i-cannot-use-as-entry-point-in-c-sharp-app-a-generic-type

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