c# readline鎬庢牱瀹炵幇瀵嗙爜杈撳叆鍔熻兘
鍦–#涓紝鍙互浣跨敤Console绫荤殑ReadKey鏂规硶鏉ュ疄鐜板瘑鐮佽緭鍏ュ姛鑳斤紝绀轰緥濡備笅锛?/p>
using System;
class Program
{
static void Main()
{
Console.Write("璇疯緭鍏ュ瘑鐮侊細");
string password = GetPassword();
Console.WriteLine("\n鎮ㄨ緭鍏ョ殑瀵嗙爜鏄細" + password);
}
static string GetPassword()
{
string password = "";
ConsoleKeyInfo key;
do
{
key = Console.ReadKey(true);
if (key.Key != ConsoleKey.Enter)
{
password += key.KeyChar;
Console.Write("*");
}
}
while (key.Key != ConsoleKey.Enter);
return password;
}
}
杩愯绋嬪簭鍚庯紝杈撳叆鐨勫瘑鐮佸皢浼氫互鏄熷彿(*)鏄剧ず锛屼繚鎶ゅ瘑鐮佺殑瀹夊叏鎬с€?/p>
相关问答