TreatControlCAsInput问题。这是一个bug吗?

问题描述 投票:12回答:2

刚刚碰到了下面描述的问题。如果 "Console.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();
c# .net .net-4.0
2个回答
14
投票

它是一个 已知问题 与Windows控制台子系统,并且早在2006年就已经在Microsoft Connect上报道过。

作者:微软 发布于22052007年12:37

你好,ARos,感谢你在System.Console中报告这个问题。该行为存在于Windows Console子系统中,正如所附的Win32 C应用程序所演示的那样。我已经向Windows Console子系统所有者报告了这个问题。

谢谢你,Josh


3
投票

不是框架上的bug,但它看起来像一个bug。视窗控制台子系统.

© www.soinside.com 2019 - 2024. All rights reserved.