运行时如何知道哪个类包含 C# 应用程序中的 Main 方法?

发布于 2025-01-05 05:31:31 字数 109 浏览 1 评论 0原文

我知道对于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如痴如狂 2025-01-12 05:31:31

编译器会查找

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 the string[] argument. You only need to specifically set the project setting if you have multiple classes with Main() functions.

Here's MSDN's detailed answer for you.

我为君王 2025-01-12 05:31:31

入口点可以在项目设置中配置。

Entry Point can be configured in Project Settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文