zoukankan      html  css  js  c++  java
  • C#控制台明/暗文输入

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace PasswordTest
     7 {
     8     class Program
     9     {
    10         /// <summary>
    11         /// 输入
    12         /// </summary>
    13         /// <param name="isPassword">是否密码</param>
    14         /// <param name="passwordChar">密码替换字符</param>
    15         /// <returns>返回输入结果</returns>
    16         static string Input(bool isPassword, char passwordChar = '*')
    17         {
    18             string result = string.Empty;
    19 
    20             Console.Write("请输入:  ");
    21 
    22             //密码
    23             if (isPassword)
    24             {
    25                 char c;
    26                 while ((c = Console.ReadKey(true).KeyChar) != '\r')
    27                 {
    28                     result += c;
    29                     Console.Write(passwordChar);
    30                 }
    31                 Console.WriteLine();
    32             }
    33             //普通输入
    34             else
    35                 result = Console.ReadLine();
    36 
    37             return result;
    38         }
    39 
    40         //入口
    41         static void Main(string[] args)
    42         {
    43             Console.Write("请选择输入类型(明文/暗文:Y/N)");
    44 
    45             Console.WriteLine("\n您输入的结果为:{0}",
    46                 Console.ReadLine().ToUpper().Trim() == "Y" ?
    47                 Input(false) : Input(true));
    48 
    49             Console.Write("按任意键退出");
    50             Console.ReadKey(true);
    51         }
    52 
    53     }//end class
    54 }//end namespace

    //欢迎转载,请注明原创,感谢

    Never give up!
  • 相关阅读:
    Linux+Apache环境下安装SSL证书
    Linux+Tomcat环境下安装SSL证书
    nginx配置ssl证书实现https访问
    Centos7安装jenkins
    kali linux网络配置
    Docker 国内镜像的配置及使用
    centos7安装tomcat8.5
    centos7 安装nginx
    Kali linux 2018 安装 Fluxion
    mysql5.7安装
  • 原文地址:https://www.cnblogs.com/CoffeeMX/p/2872202.html
Copyright © 2011-2022 走看看