10.1 Application startup

本文主要介绍C#应用程序启动相关内容。应用启动时执行环境调用入口点方法Main,它有特定签名,可返回int值,也可带形式参数并遵循约束。C#支持方法重载,但一个程序中符合入口点条件的Main方法只能有一个。此外,入口点访问不受声明限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

10.1 Application startup
Application startup occurs when the execution environment calls a designated
method, which is referred to
as the application’s entry point. This entry point method is always named
Main, and shall have one of the
following signatures:
static void Main() {.}
static void Main(string[] args) {.}
static int Main() {.}
static int Main(string[] args) {.}
As shown, the entry point may optionally return an int value. This return
value is used in application
termination (§10.2).
The entry point may optionally have one formal parameter, and this formal
parameter may have any name. If
such a parameter is declared, it must obey the following constraints:
. The implementation shall ensure that the value of this parameter is not
null.
. Let args be the name of the parameter. If the length of the array
designated by args is greater than
zero, the array members args[0] through args[args.Length-1], inclusive,
must refer to strings,
called application parameters, which are given implementation-defined
values by the host environment
prior to application startup. The intent is to supply to the application
information determined prior to
application startup from elsewhere in the hosted environment. If the host
environment is not capable of
supplying strings with letters in both uppercase and lowercase, the
implementation shall ensure that the
strings are received in lowercase. [Note: On systems supporting a command
line, application parameters
correspond to what are generally known as command-line arguments. end note]
Since C# supports method overloading, a class or struct may contain
multiple definitions of some method,
provided each has a different signature. However, within a single program,
no class or struct shall contain
more than one method called Main whose definition qualifies it to be used
as an application entry point.
Other overloaded versions of Main are permitted, however, provided they
have more than one parameter, or
their only parameter is other than type string[].
An application can be made up of multiple classes or structs. It is
possible for more than one of these classes
or structs to contain a method called Main whose definition qualifies it to
be used as an application entry
point. In such cases, one of these Main methods must be chosen as the entry
point so that application startup
can occur. This choice of an entry point is beyond the scope of this
specification.no mechanism for
specifying or determining an entry point is provided.
In C#, every method must be defined as a member of a class or struct.
Ordinarily, the declared accessibility
(§10.5.1) of a method is determined by the access modifiers (§17.2.3)
specified in its declaration, and
similarly the declared accessibility of a type is determined by the access
modifiers specified in its
declaration. In order for a given method of a given type to be callable,
both the type and the member must be
accessible. However, the application entry point is a special case.
Specifically, the execution environment
can access the application’s entry point regardless of its declared
accessibility and regardless of the declared
accessibility of its enclosing type declarations.
In all other respects, entry point methods behave like those that are not
entry points.
D:\Plug\Tomcat\tomcat10\bin\catalina.bat run [2025-03-31 06:10:13,027] 工件 NatatoriumSystem:Web exploded: 正在等待服务器连接以启动工件部署… Using CATALINA_BASE: "C:\Users\minek\AppData\Local\JetBrains\IntelliJIdea2024.3\tomcat\64078e34-dfb3-4c2b-b365-d98e28ce61b7" Using CATALINA_HOME: "D:\Plug\Tomcat\tomcat10" Using CATALINA_TMPDIR: "D:\Plug\Tomcat\tomcat10\temp" Using JRE_HOME: "C:\Program Files\Java\jdk-17" Using CLASSPATH: "D:\Plug\Tomcat\tomcat10\bin\bootstrap.jar;D:\Plug\Tomcat\tomcat10\bin\tomcat-juli.jar" Using CATALINA_OPTS: "" 31-Mar-2025 18:10:13.610 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log Server.�������汾: Apache Tomcat/10.1.39 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log ����������: Mar 4 2025 19:02:32 UTC 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log �������汾��: 10.1.39.0 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log ����ϵͳ����: Windows 11 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log OS.�汾: 10.0 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log �ܹ�: amd64 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log Java ��������: C:\Program Files\Java\jdk-17 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log Java������汾: 17.0.12+8-LTS-286 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.��Ӧ��: Oracle Corporation 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\minek\AppData\Local\JetBrains\IntelliJIdea2024.3\tomcat\64078e34-dfb3-4c2b-b365-d98e28ce61b7 31-Mar-2025 18:10:13.611 ��Ϣ [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: D:\Plug\Tomcat\tomcat10
最新发布
04-01
E:\study\tomcat\apache-tomcat-10.1.7-windows-x64\apache-tomcat-10.1.7\bin\catalina.bat run [2025-03-29 12:49:44,850] Artifact SharesViews:war exploded: Waiting for server connection to start artifact deployment... Using CATALINA_BASE: "C:\Users\fds\AppData\Local\JetBrains\IntelliJIdea2023.2\tomcat\e128b7f3-9212-4985-bb18-60573139d5e5" Using CATALINA_HOME: "E:\study\tomcat\apache-tomcat-10.1.7-windows-x64\apache-tomcat-10.1.7" Using CATALINA_TMPDIR: "E:\study\tomcat\apache-tomcat-10.1.7-windows-x64\apache-tomcat-10.1.7\temp" Using JRE_HOME: "E:\jdk17" Using CLASSPATH: "E:\study\tomcat\apache-tomcat-10.1.7-windows-x64\apache-tomcat-10.1.7\bin\bootstrap.jar;E:\study\tomcat\apache-tomcat-10.1.7-windows-x64\apache-tomcat-10.1.7\bin\tomcat-juli.jar" Using CATALINA_OPTS: "" 29-Mar-2025 00:49:45.521 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/10.1.7 29-Mar-2025 00:49:45.524 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Feb 27 2023 20:25:27 UTC 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号: 10.1.7.0 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Windows 10 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 10.0 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd64 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: E:\jdk17 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 17.0.1+12-LTS-39 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation 29-Mar-2025 00:49:45.525 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\fds\AppData\Local\JetBrains\In
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值