为什么Main方法私有?方法、Main

2023-09-02 10:28:54 作者:烟雨墨冷竹离殇

新的控制台项目模板创建了一个主要的方法是这样的:

New console project template creates a Main method like this:

class Program
{
    static void Main(string[] args)
    {
    }
}

为什么,无论是的方法,也不是计划类必须公开?

Why is it that neither the Main method nor the Program class need to be public?

推荐答案

程序的入口点是标有 .entrypoint IL指令。这不要紧,如果该方法或类是公共与否,最重要的事情是这样的指令。

The entry point of a program is marked with the .entrypoint IL directive. It does not matter if the method or the class is public or not, all that matters is this directive.