意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

c# readline怎样实现密码输入功能

来源:佚名 编辑:佚名
2024-06-24 14:07:33

在C#中,可以使用Console类的ReadKey方法来实现密码输入功能,示例如下:

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;
    }
}

运行程序后,输入的密码将会以星号(*)显示,保护密码的安全性。


c# readline怎样实现密码输入功能

本网站发布或转载的文章均来自网络,其原创性以及文中表达的观点和判断不代表本网站。
上一篇: c# readline如何限制输入长度 下一篇: c# readline如何读取大文件