1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
string username = "admin";
string password = "88888";
Console.WriteLine("請輸入帳號");
string id = Console.ReadLine()!;
Console.WriteLine("請輸入密碼");
string pw = Console.ReadLine()!;
//第一種情況:帳號密碼都正確
if (id == username && pw == password)
{
Console.WriteLine("登入成功");
}
//第二種情況:密碼錯誤
else if (id == username)
{
Console.WriteLine("密碼錯誤,程式退出");
}
//第三種情況:帳號錯誤
else if (pw == password)
{
Console.WriteLine("帳號錯誤,程式退出");
}
//第四種情況:帳號密碼全都錯
else
{
Console.WriteLine("帳號密碼錯誤,程式退出");
}
Console.ReadKey();
[C# 筆記] 帳號密碼判斷
This post is licensed under CC BY 4.0 by the author.