c# - 停止程序退出/终止,直到用户键入 exit

标签 c#

{
Console.WriteLine("Whatever you type, You will get same Output");
string userValue;
userValue = Console.ReadLine();
Console.WriteLine("Your written Words Are: " + userValue);
Console.ReadLine();
}

我的代码没有任何问题,只是我不希望在用户编写任何内容时控制台关闭。 例如如果用户输入 ABC,则控制台应该显示“您输入了 ABC”。程序应该询问您想输入更多内容吗?如果用户写"is",则再次键入,直到用户键入“退出”,然后程序应终止。

最佳答案

您需要将其放入循环中,如下所示:

string userValue;
do
{
    Console.WriteLine("Whatever you type, You will get same Output");
    userValue = Console.ReadLine();
    Console.WriteLine("Your written Words Are: " + userValue);
}
while(userValue != "Exit");

关于c# - 停止程序退出/终止,直到用户键入 exit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34973268/

相关文章:

c# - 在 NET Core 中调用从 C++ 项目构建的 .dll 时出现 BadImageFormatException

c# - 类似于 c# 的 javah

c# - Word VSTO 覆盖 CTRL+Z/CTRL+Y

c# - 在 RibbonQuickAccessToolBar 中无法访问 AddChild()

c# - 如何检查枚举数组中是否存在枚举值?

c# - Xamarin Android 将数据从类传递到 Activity

c# - 如何将对象保存到 Visual Studio 中的 fooSettings.settings 文件?

c# - ISO6937 转 UTF8 在 C# 中给出错误结果

c# - 使用 C# 将 bool 数组转换为字符串

c# - System.NotSupportedException : Cannot compile: TypeAs At SQLite. 表查询