"); string test =-6ren">
gpt4 book ai didi

c# - 如何在不需要输入的情况下退出控制台应用程序

转载 作者:行者123 更新时间:2023-11-30 21:05:43 25 4
gpt4 key购买 nike

当用户键入 x 而无需按回车键时退出应用程序的最佳方式是什么。我目前使用的代码是这样的:

Console.WriteLine("\nType x to exit > ");
string test = Console.ReadLine();
while (test != "x")
{
Console.WriteLine("\nType x to exit > ");
test = Console.ReadLine();
}

这将使用户体验更好。

最佳答案

您可以使用 Console.ReadKey相反。

Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.

关于c# - 如何在不需要输入的情况下退出控制台应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11532074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com