如果我在C#中的Main方法是私有的,为什么我的程序可以工作?

如果我在C#中的Main方法是私有的,为什么我的程序可以工作?

问题描述:

默认情况下,类中每个成员的类型修饰符都是私有的,即使Main()函数类型修饰符也是私有的.CLR如何调用外部看不见的main方法?

By default the type modifier for every member in a class is a private, even the Main() function type modifier is private. How does the CLR call the main method which is not visible to the outside world?

没错.

Thats not true.

它必须是公开的.例如 public static void Main().

It has to be public. For e.g. public static void Main().

这是我发现的&今天学习,了解为什么 Main 不需要 public 的原因. http://social.msdn.microsoft.com/forums/zh-CN/csharpgeneral/thread/9184c55b-4629-4fbf-ad77-2e96eadc4d62/

Here is what I found & learned today, on why Main need not be public. http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/9184c55b-4629-4fbf-ad77-2e96eadc4d62/