zoukankan      html  css  js  c++  java
  • 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace ConsoleApplication7
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             string result;
    14             Console.WriteLine("请输入用户名");
    15             string name = Console.ReadLine();
    16             Console.WriteLine("请输入密码");
    17             string password = Console.ReadLine();
    18             if (Test(name, password, out result))
    19             {
    20                 Console.WriteLine(result);
    21             }
    22             else
    23             {
    24                 Console.WriteLine(result);
    25             }
    26             Console.ReadKey();
    27         }
    28 
    29         static bool Test(string name, string password, out string result)
    30         {
    31             if (name == "admin" && password == "123")
    32             {
    33                 result = "登录成功";
    34                 return true;
    35             }
    36             else if (name == "admin")
    37             {
    38                 result = "密码错误";
    39                 return false;
    40             }
    41             else
    42             {
    43                 result = "用户名错误";
    44                 return false;
    45             }
    46         }
    47     }
    48 }
  • 相关阅读:
    2.4 将类内联化
    2.3 提炼类
    2.2 搬移字段
    2.1 搬移函数
    1.8 替换你的算法
    1.7 以函数对象取代函数
    1.7 移除对参数的赋值动作
    1.6 分解临时变量
    1.5 引入解释性变量
    1.4 以查询取代临时变量
  • 原文地址:https://www.cnblogs.com/start-from-scratch/p/5058211.html
Copyright © 2011-2022 走看看