|
|
static void Main(string[] args) { string password = string.Empty; ConsoleKeyInfo info; do { info = Console.ReadKey(true); if (info.Key != ConsoleKey.Enter && info.Key != ConsoleKey.Backspace && info.Key != ConsoleKey.Escape && info.Key != ConsoleKey.Tab && info.KeyChar != '\0') { password += info.KeyChar; Console.Write('*'); } } while (info.Key != ConsoleKey.Enter); Console.WriteLine(); Console.WriteLine(password); }
if
是判断按键是否为可打印字符键。 |
|