[英]Console application closes immediately after opening in visual studio
[英]Console.SetIn() immediately closes console application
我刚刚了解了Console.SetIn()函数,并对其进行了尝试。 即使我的主方法以Console.ReadLine()结尾,它仍会立即关闭控制台应用程序。
这是代码:
static void Main(string[] args) {
Console.SetIn(new StreamReader("example.txt"));
string[] input = Console.ReadLine().Split();
int L = int.Parse(input[0]);
int m = int.Parse(input[1]);
string[] lelijk = Console.ReadLine().Split();
Console.ReadLine();
}
这是在example.txt中:
40 0
Hello world!
Console.ReadKey();
在主体末尾使用它。 它将等待按键,然后控制台将关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.