为什么我不能在C#应用程序中使用泛型类型的入口点? [英] Why I cannot use as entry point in C# app a generic type?

查看:145
本文介绍了为什么我不能在C#应用程序中使用泛型类型的入口点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,Main方法必须是非泛型类型才能被选为入口点。为什么会这样?



我对此有点困惑,因为这在Java中是可能的(函数main()可以在泛型类中)。

 命名空间ConsoleApplication 
{
class Program< T> //不正确的
{
static void Main(string [] args)
{
}
}
}
Main
方法可以作为一个固定的方法来使用。 接口到操作系统,它本身没有机制来选择和指定一个类型作为参数。


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)
        {
        }
    }
}

解决方案

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.

这篇关于为什么我不能在C#应用程序中使用泛型类型的入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆