只是碰到了下面描述的問題。如果「Console.TreatControlCAsInput = true;」,則必須在ReadLine()上按[enter]兩次。TreatControlCAsInput問題。這是一個錯誤?
我已經在下面寫了一些演示代碼。我正確地猜測這段代碼在.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();
你運行這個什麼平臺上? – Oded
我可以在Windows 7上重現這一點。回車似乎正在做** HOME **按鈕的功能 –
我在2006年看到它在報告中標記爲關閉的設計。 http://connect.microsoft.com/VisualStudio/feedback/details/226101/console-treatcontrolcasinput-true-breaks-readline – automatic