新人求教

解决方案 »

  1.   

    using System;
    using System.Text;
    class test
    {
    static string ReadPassword ()
    {
    StringBuilder ret = new StringBuilder();
    ConsoleKeyInfo key;
    while (true)
    {
     key = Console.ReadKey(true);
     if (key.Key == ConsoleKey.Enter)
       break;
     if (char.IsLetterOrDigit (key.KeyChar) || 
       char.IsWhiteSpace (key.KeyChar) ||
       char.IsPunctuation (key.KeyChar))
     {
       Console.Write ("*");
       ret.Append (key.KeyChar);
     }

    }
    Console.WriteLine ();
    return ret.ToString();
    }
    static void Main ()
    {
    Console.WriteLine ("输入密码:");
    string pwd = ReadPassword();
    Console.WriteLine ("密码:{0}",pwd);
    }
    }随便写了一个,不支持退格和移动光标...不过一般来说够用了.