[英].NET Console.Readline doesn't read the first line entered
I wrote a console application but the first input line is always ignored. 我编写了一个控制台应用程序,但始终忽略第一行输入。
static void Main(string[] args)
{
try
{
string line;
while ((line = Console.ReadLine()) != "exit")
{
string input = Console.ReadLine().ToString();
Console.WriteLine("I wrote: " + input);
}
}
catch (Exception ex)
{
throw ex;
}
}
When I run this, the result is as follows: 当我运行它时,结果如下:
Any ideas why this is happening? 任何想法为什么会这样? I already tried writing a line before the first line, but the same problem occurs. 我已经尝试在第一行之前写一行,但是会出现相同的问题。
This way: 这条路:
static void Main(string[] args)
{
try
{
string line;
while ((line = Console.ReadLine()) != "exit")
{
Console.WriteLine("I writed: " + line);
string input = Console.ReadLine().ToString();
Console.WriteLine("I writed: " + input);
}
}
catch (Exception ex)
{
throw ex;
}
}
You were printing only input
and never line
您只打印input
而没有line
Maybe you wanted to do it this way: 也许您想这样做:
static void Main(string[] args)
{
try
{
string input;
while ((input = Console.ReadLine()) != "exit")
{
Console.WriteLine("I writed: " + input);
}
}
catch (Exception ex)
{
throw ex;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.