在Console.ReadLine()语句之前加入Console.ReadKey()语句
时间: 2024-01-10 20:03:07 浏览: 132
在使用C#中的`Console.ReadLine()`语句时,如果程序运行结束太快导致输出结果无法被看到,可以在`Console.ReadLine()`语句之前加入`Console.ReadKey()`语句,以便程序暂停等待用户输入,直到用户按下回车键后才会退出。以下是示例代码:
```csharp
Console.WriteLine("请输入一个数字:");
int num = int.Parse(Console.ReadLine());
Console.WriteLine("你输入的数字是:" + num);
Console.WriteLine("按下任意键继续...");
Console.ReadKey();
```
在上面的示例代码中,`Console.ReadKey()`语句会在用户按下任意键后才会退出程序,这样就可以看到输出结果了。
阅读全文