foreach (Uers item in userGroup) //第一段
{
Console.WriteLine("請輸入賬號");
string idC1 = Console.ReadLine();
Console.WriteLine("請輸入密碼");
string pwd1 = Console.ReadLine();
if (idC1.Equals(item.idC) && pwd1.Equals(item.pwd))
{
Console.WriteLine("請輸入要取得的金額");
double _banlance = double.Parse(Console.ReadLine());
if (_banlance <= item.banlance || _banlance != 0)
{
item.banlance = item.banlance - _banlance;
Console.WriteLine("余額:{0}", item.banlance);
}
else
{
Console.WriteLine("金額輸入有誤!請重新輸入");
}
}
else
{
Console.WriteLine("密碼輸入有誤!請重新輸入");
drawmoney();
}
}
/* Console.WriteLine("請輸入賬號"); //第二段
string idcc = Console.ReadLine();
Console.WriteLine("請輸入密碼");
string _pwd = Console.ReadLine();
if (idcc.Equals(u.idC) && _pwd.Equals(u.pwd))
{
Console.WriteLine("請輸入要取得金額");
double _banlance = double.Parse(Console.ReadLine());
if (_banlance <= u.banlance || _banlance != 0)
{
u.banlance = u.banlance - _banlance;
Console.WriteLine("余額:{0}", u.banlance);
}
else
{
Console.WriteLine("金額輸入有誤!請重新輸入");
}
}
else
{
Console.WriteLine("密碼輸入有誤!請重新輸入");
drawmoney();
} */
代碼類似的可以寫為一個方法然後傳參數即可