文档及代码下载:http://www.dingos.cn/index.php?topic=1700.0 using System; using System.Text; class KeyNumber{ public static void Main(){ Console.Write("Input a password: "); StringBuilder sb = new StringBuilder(); while (true){ ConsoleKeyInfo cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.Enter){ Console.WriteLine(); break; } if (cki.Key == ConsoleKey.Backspace){ if (sb.Length > 0){ Console.Write("/b/0/b"); sb.Length--; } continue; } Console.Write('*'); sb.Append(cki.KeyChar); } Console.WriteLine("Your password is: {0}", sb.ToString()); } }