日期:2014-05-18 浏览次数:21180 次
Console.Write("用户名:"); string user = Console.ReadLine(); Console.Write("密码:"); string password = Console.ReadLine();
------解决方案--------------------
static void Main(string[] args) { string userTip="User:"; string pwdTip="Password:"; Console.WriteLine(userTip); Console.WriteLine(pwdTip); Console.SetCursorPosition(userTip.Length, 0); string user = Console.ReadLine(); Console.SetCursorPosition(pwdTip.Length, 1); StringBuilder password = new StringBuilder(); while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Enter) { Console.WriteLine(); break; } else if (keyInfo.Key == ConsoleKey.Backspace && password.Length > 0) { Console.Write('\0'); Console.CursorLeft--; password.Remove(password.Length - 1, 1); } else { //这里如果有需要的话,过滤一下不允许的字符,包括方向键之类的 password.Append(keyInfo.KeyChar); Console.CursorLeft--; Console.Write("*"); } } Console.WriteLine(string.Concat("--- Input ---\r\n",userTip, user,"\r\n", pwdTip, password)); Console.ReadLine(); }
------解决方案--------------------
。。打错了。。是Console.ReadLine();