运行时如何知道哪个类包含 C# 应用程序中的 Main 方法?
我知道对于 C# 中的控制台/Windows 应用程序,“Main”方法是运行应用程序的入口点。
如果我们的应用程序中有数百个类,运行时将如何检测哪个类包含“Main”方法来运行应用程序?
I know that for Console/Windows application in C#, "Main" method is entry point to run the application.
If we have hundreds of classes in our application, how the runtime will detect which class contains the "Main" method to run the application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编译器会查找
static void Main(string[])
或
static int Main(string[])
来确定入口点。
Main()
也可以在不使用string[]
参数的情况下声明。如果您有多个带有Main()
函数的类,则只需专门设置项目设置。这是 MSDN 为您提供的详细答案。
The compiler looks for
static void Main(string[])
or
static int Main(string[])
to determine the entry point.
Main()
may also be declared without thestring[]
argument. You only need to specifically set the project setting if you have multiple classes withMain()
functions.Here's MSDN's detailed answer for you.
入口点可以在项目设置中配置。
Entry Point can be configured in Project Settings.