TreatControlCAsInput问题.这是臭虫吗?
本文关键字:问题 TreatControlCAsInput | 更新日期: 2023-09-27 18:14:53
刚刚遇到下面描述的问题。如果"控制台。TreatControlCAsInput = true;",你必须在ReadLine()上按两次[enter]。
我在下面写了一些演示代码。我猜对了,这段代码演示了。net 4框架中的一个bug。
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();
这是Windows控制台子系统的一个已知问题,早在2006年就在Microsoft Connect上报告过。
由Microsoft于22/05/2007 at 12:37发布
你好,ARos,感谢您在System.Console中报告此问题。的行为存在于Windows控制台子系统中,如所示附带的Win32 C应用程序。我已经报告了这个问题Windows控制台子系统的所有者。
谢谢,杰克
不是框架上的bug,但看起来像是Windows控制台子系统的bug。