在主函數中提示用戶輸入用戶名和密碼。另寫一方法來判斷用戶輸入是否正確。該方法分別返回一個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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM