• 使用out参数做登陆


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入用户名");
                string name = Console.ReadLine();
                Console.WriteLine("请输入密码");
                string pwd = Console.ReadLine();
                
                string msg;
                bool b = IsLogin(name,pwd,out msg);
                Console.WriteLine();
                Console.WriteLine("登陆结果:{0}",b);
                Console.WriteLine("登陆信息:{0}", msg);
                Console.ReadKey();
            }
            
            
            /// <summary>
            /// 判断登陆是否成功
            /// </summary>
            /// <param name="name">用户名</param>
            /// <param name="pwd">密码</param>
            /// <param name="msg">多余返回信息</param>
            /// <returns>登陆布尔值</returns>
            public static bool IsLogin(string name,string pwd,out string msg)
            {
                if(name == "admin" && pwd == "888888")
                {
                    msg = "登陆成功";
                    return true;
                }
                else if(name=="admin")
                {
                    msg = "密码错误";
                    return false;
                }
                else if(pwd =="888888")
                {
                    msg = "用户名错误";
                    return false;
                }
                else
                {
                    msg = "两者错误";
                    return false;
                }
               
            }
        }
    }
  • 相关阅读:
    安装express 新建项目遇到问题汇总
    Java IO
    python3基础之“函数(1)”
    python3基础之“小练习(3)”
    python3基础之“小练习(2)”
    python3基础之“小练习(1)”
    linux命令
    1.环境安装部署汇总
    阶段13-直播~
    docker环境问题
  • 原文地址:https://www.cnblogs.com/blacop/p/5954907.html
Copyright © 2020-2023  润新知