C# 控制台程序Console.ReadKey的用法

Console.ReadKey按下的键会显示在控制台窗口上,但是按backspace却无法删除回退,怎么解决?

 1 public string ReadLine()
 2         {
 3             string ReadString = "";
 4             while (true)
 5             {                
 6                 ConsoleKey InputKey = Console.ReadKey().Key;
 7                 if (InputKey != ConsoleKey.Enter)
 8                 {
 9                     if (InputKey == ConsoleKey.Backspace)
10                     {
11                         if (ReadString != "")
12                         {
13                             ReadString = ReadString.Substring(0, ReadString.Length - 1);
14                         }
15                     }
16                     else
17                     {
18                         ReadString = ReadString + ((char)InputKey.GetHashCode()).ToString();
19                     }
20                 }
21                 else
22                 {
23                     break;
24                 }
25 
26                 if (InputKey == ConsoleKey.Escape)
27                 {
28                     ReadString = "ESC";
29                     break;
30                 }
31             }
32 
33             return ReadString;
34         }
   

初始化string ReadString = ""了 所以if (ReadString != "") 总是为false

初始化ReadString是在while死循环的外面,所以不会总是为false啊
按了backspace后方法没返回啊,你的ReadString没返回啊
@candyjun:按了backspace后方法没返回啊,你的ReadString没返回啊

@john23.net: 如果想實現 backspace退格,應該是判斷接受的readkey()值爛定位光標.