为什么 Main 方法是私有的? [英] Why is Main method private?

查看:15
本文介绍了为什么 Main 方法是私有的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的控制台项目模板创建一个 Main 方法,如下所示:

New console project template creates a Main method like this:

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

为什么Main 方法和Program 类都不需要公开?

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.

这篇关于为什么 Main 方法是私有的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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