TreatControlCAsInput问题.这是一个错误吗?

Con*_*ngo 12 .net c# .net-4.0

刚碰到下面描述的问题.如果"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)

Joh*_*mer 14

这是Windows控制台子系统的已知问题,并且已于2006年在Microsoft Connect上报告.

微软于2007年5月22日12:37发布

您好AROS,感谢您在System.Console中报告此问题.Windows控制台子系统存在该行为,如附带的Win32 C应用程序所示.我已将此问题报告给Windows控制台子系统所有者.

谢谢,乔希

  • 作为旁注:连接项已被关闭为"按设计".所以听起来他们认为这是一个功能. (2认同)