C# Console - hide the input from console window while typing

后端 未结 5 2008
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 18:56

I\'m using Console.ReadLineto read the input of the user. However, I want to hide/exclude the inputted text on the console screen while typing. For example, whe

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 19:50

    Here is a short implementation. thx @ojblass for the idea

    System.Console.Write("password: ");
    string password = null;
    while (true)
    {
        var key = System.Console.ReadKey(true);
        if (key.Key == ConsoleKey.Enter)
            break;
        password += key.KeyChar;
    }
    

提交回复
热议问题