您好,我是 C# 新手,我想制作一个简单的 C# 密码程序,用户只能输入 3 次或尝试输入 3 次密码,程序将使用 Application.Exit() 退出;
但似乎循环使 MessageBox 一直很烦人,并且不允许用户在接下来的 2 次尝试中按下或键入按钮。
请帮助我吗?
用这个编辑但是“使用'pin'的未命名局部变量”的错误T_T:
private int _failedAttempts = 0;
private void btnEtr_Click(object sender, System.EventArgs e)
{
int pin;
if (pin != 21)
{
if (pin !=21)
{
_failedAttempts++;
MessageBox.Show ("Fail. " + (3 - _failedAttempts) + " attempts more.", "EPIC FAIL", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
if(_failedAttempts == 3)
{
Application.Exit();
}
}
}
else
{
MessageBox.Show ("Welcome. Your pin is CORRECT", "CONGRATULATIONS",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}