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 }