刚碰到下面描述的问题.如果"Console.TreatControlCAsInput = true;",则必须在ReadLine()上按[enter]两次.
我在下面写了一些演示代码.我猜测这个代码演示了.NET 4框架中的错误,这是正确的吗?
Console.Write("Test 1: Console.TreatControlCAsInput = false\nType \"hello\": ");
{
string readline = Console.ReadLine(); // type "hello" [enter].
Console.WriteLine("You typed: {0}", readline);
// Prints "hello".
}
Console.Write("Test 2: Console.TreatControlCAsInput = true\nType \"hello\": ");
Console.TreatControlCAsInput = true;
{
string readline = Console.ReadLine(); // type "hello" [enter].
Console.WriteLine("You typed: {0}", readline);
// Should print "hello" - but instead, you have to press [enter]
// *twice* to complete the ReadLine() command, and it adds a "\r"
// rather than a "\n" to the output (so it overwrites the original line)
}
// This bug is a fatal error, because it makes all ReadLine() commands unusable.
Console.Write("[any key to exit]");
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
883 次 |
| 最近记录: |