1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _08使用out参数做登陆 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 //分别的提示用户输入用户名和密码 14 //你写一个方法来判断用户输入的是否正确 15 //返回给用户一个登陆结果,并且还要单独的返回给用户一个登陆信息 16 //如果用户名错误,除了返回登陆结果之外,还要返回一个 "用户名错误" 17 //“密码错误” 18 Console.WriteLine("请输入用户名"); 19 string userName = Console.ReadLine(); 20 Console.WriteLine("请输入密码"); 21 string userPwd = Console.ReadLine(); 22 string msg; 23 bool b = IsLogin(userName, userPwd, out msg); 24 Console.WriteLine("登陆结果{0}",b); 25 Console.WriteLine("登陆信息{0}",msg); 26 Console.ReadKey(); 27 } 28 /// <summary> 29 /// 判断登陆是否成功 30 /// </summary> 31 /// <param name="name">用户名</param> 32 /// <param name="pwd">密码</param> 33 /// <param name="msg">多余返回的登陆信息</param> 34 /// <returns>返回登陆结果</returns> 35 public static bool IsLogin(string name, string pwd, out string msg) 36 { 37 if (name == "admin" && pwd == "888888") 38 { 39 msg = "登陆成功"; 40 return true; 41 } 42 else if (name == "admin") 43 { 44 msg = "密码错误"; 45 return false; 46 } 47 else if (pwd == "888888") 48 { 49 msg = "用户名错误"; 50 return false; 51 } 52 else 53 { 54 msg = "未知错误"; 55 return false; 56 } 57 } 58 } 59 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _10ref参数 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 double salary = 5000; 14 JiangJin(ref salary); 15 Console.WriteLine(salary); 16 Console.ReadKey(); 17 } 18 19 public static void JiangJin(ref double s) 20 { 21 s += 500; 22 23 } 24 25 public static void FaKuan(double s) 26 { 27 s -= 500; 28 } 29 } 30 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _10ref参数 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 double salary = 5000; 14 JiangJin(ref salary); 15 Console.WriteLine(salary); 16 Console.ReadKey(); 17 } 18 19 public static void JiangJin(ref double s) 20 { 21 s += 500; 22 23 } 24 25 public static void FaKuan(double s) 26 { 27 s -= 500; 28 } 29 } 30 }
原文:http://www.cnblogs.com/ggsdduzbl/p/4930768.html