我有一个简单的.NET控制台应用程序,它只是一个较大应用程序的测试部分。我想指定控制台应用程序的“退出代码”。我该如何做?
net helpmsg decimal_code
net helpmsg 1
返回值
Incorrect function
Environment.Exit(0);
如果您不想返回任何内容,请将int设为0。
int exitCode = 0;
Environment.Exit(exitCode);
或者你可以抛出一个错误(个人偏好):
throw new ArgumentException("Code 0, Environment Exit");
我选择了ArgumentException,但你可以输入其他的。它也能正常工作。
另一种方式:
public static class ApplicationExitCodes
{
public static readonly int Failure = 1;
public static readonly int Success = 0;
}