A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 夜猫子进宅 中级黑马   /  2014-6-15 03:11  /  1243 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 夜猫子进宅 于 2014-6-15 12:18 编辑

在控制台中提示用户输入用户名和密码,写一个方法判断用户是否登录成功,如果登录成功,返回true,并且返回”登录成功”,登录失败返回false,并且返回”登录失败”(提示:使用out参数)      

评分

参与人数 1技术分 +1 收起 理由
张旭辉 + 1

查看全部评分

3 个回复

倒序浏览
  1.        static void Main(string[] args)
  2.         {
  3.             Console.Write("请输入用户名:");
  4.             string userName = Console.ReadLine();
  5.             Console.Write("请输入密码:");
  6.             string userPwd = Console.ReadLine();
  7.             string str;
  8.             bool b = Test(userName, userPwd, out str);
  9.             Console.WriteLine("返回值{0},登陆状态:{1}", b, str);
  10.             Console.ReadKey();
  11.         }

  12.         public static bool Test(string userName, string userPwd, out string str)
  13.         {
  14.             if (userName == "admin" && userPwd == "123456")
  15.             {
  16.                 str = "登陆成功";
  17.                 return true;
  18.             }
  19.             else
  20.             {
  21.                 str = "登陆失败";
  22.                 return false;
  23.             }
  24.         }
复制代码

评分

参与人数 1技术分 +1 收起 理由
张旭辉 + 1

查看全部评分

回复 使用道具 举报 1 0

不错   {:3_68:}崇拜中…   
回复 使用道具 举报
我用三元表达式写了这个   哈哈,代码 少了一点
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             //在控制台中提示用户输入用户名和密码,写一个方法判断用户是否登录成功,
  6.             //如果登录成功,返回true,并且返回”登录成功”,登录失败返回false,
  7.             //并且返回”登录失败”(提示:使用out参数)
  8.             string result;
  9.             Console.WriteLine("请输入用户名:");
  10.             string userName = Console.ReadLine();
  11.             Console.WriteLine("请输入密码:");
  12.             string pwd = Console.ReadLine();
  13.             bool isTrue = Login(userName, pwd, out result);
  14.             Console.WriteLine(isTrue);
  15.             Console.WriteLine(result);
  16.             Console.ReadKey();
  17.         }
  18.         static bool Login(string userName, string pwd, out string result)
  19.         {
  20.             bool isTrue=userName == "admin" && pwd == "888888"?true:false;
  21.             result = isTrue ? "登录成功" : "登录失败";
  22.             return isTrue;
  23.            
  24.         }
  25.     }
复制代码

评分

参与人数 1技术分 +1 收起 理由
czwanglei + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马