Chỉ cần chạy qua vấn đề được mô tả bên dưới. Nếu "Console.TreatControlCAsInput = true;", bạn phải nhấn [enter] hai lần trên ReadLine().TreatControlCAsInput issue. Đây có phải là một lỗi?
Tôi đã viết một số mã demo bên dưới. Tôi chính xác trong phỏng đoán rằng mã này chứng tỏ một lỗi trong khuôn khổ .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();
nền tảng gì bạn đang chạy này trên? – Oded
Tôi có thể tạo lại điều này trên Windows 7. Nhập có vẻ như đang thực hiện chức năng của nút ** HOME ** –
Tôi thấy báo cáo được báo cáo vào năm 2006, nơi được đánh dấu là đã đóng, theo thiết kế. http://connect.microsoft.com/VisualStudio/feedback/details/226101/console-treatcontrolcasinput-true-breaks-readline – automatic