我试图接近我的C#控制台应用程序(不调试运行),并没有什么工作。我已经尝试了所有不同的退出代码,但没有通常的嫌疑人被终止它= /是不是因为该选项是在一堆嵌套的if语句?它可能是一个非常简单的东西,我想念但是它伤害了我的大脑现在有人请帮助!我已经试过:终止C#控制台应用程序
System.Environment.Exit(0);
System.Environment.Exit(1);
System.Environment.Exit(-1);
return;
Application.Exit(); //(wont even except it)
上下文是否有助于我已经使用嵌套的if语句来检查,如果用户已经输入的数字或字母“Q”,如果他们输入数字的计算进行,如果已经输入了字母q,那么程序将退出,并输出任何其他错误语句。
string userInput;
int userInputDigit = 0;
double userCost = 0;
char userInputChar;
userInput = Convert.ToString(Console.ReadLine());
if (int.TryParse(userInput, out userInputDigit))
{
if (userInputDigit <= 50)
{
userCost = (price * userInputDigit);
Console.WriteLine("You have purchased {0} Widgets at a cost of {1:c0}", userInputDigit, userCost);
}
else if ((userInputDigit > 50) && (userInputDigit <= 80))
{
userCost = (price * 50) + ((userInputDigit - 50) * (price - 1));
Console.WriteLine("You have purchased {0} Widgets at a cost of {1:c0}", userInputDigit, userCost);
}
else if ((userInputDigit > 80) && (userInputDigit <= 100))
{
userCost = (price * 50) + (30 * (price - 1)) + ((userInputDigit - 80) * (price - 2.50));
Console.WriteLine("You have purchased {0} Widgets at a cost of {1:c0}", userInputDigit, userCost);
}
else
{
Console.WriteLine("Error! Please input a number between 0 and 100");
}
}
else if (char.TryParse(userInput, out userInputChar))
{
if ((userInput == "q") || (userInput == "Q"))
{
System.Environment.Exit(0);
}
else
{
Console.WriteLine("Incorrect Letter Inputted");
}
}
else
{
Console.WriteLine("Error! Please input a number or 'q' to quit");
}
你好吗?您是否在Visual Studio中选择了“Debug - > Start without Debugging”?你是否手动打开控制台窗口,然后输入.exe名称? –
所以你写了一个控制台程序,你大概是从命令行运行它的。当执行到达主函数的末尾时它应该自行退出。如果你注释掉main中的所有内容,构建你的程序并运行它,它应该运行并退出。可以? –
在调试器中,检查“System.Environment.Exit(0)”是否被执行。 – millimoose