我有一个带有数字按钮的“安全面板”,允许用户在TextBox
控件中输入密码(代码)。我正在switch
声明中处理此密码。
问题:当用户输错密码时,我想显示“拒绝访问”的日期和时间。我怎么能这样做?
代码:
string password = inputtxt.Text;
switch (password)
{
case "1432":
listBox.Items.Add(DateTime.Now + " " + "INFO First Year Students");
break;
case "2543":
listBox.Items.Add(DateTime.Now + " " + "INFO Second Year Students");
break;
case "3543":
listBox.Items.Add(DateTime.Now + " " + "B.Tech Students");
break;
case "2645":
case "2646":
case "2647":
case "2648":
listBox.Items.Add(DateTime.Now + " " + "CSIT Faculty");
break;
case "8888":
listBox.Items.Add(DateTime.Now + " " + "IET Staff");
break;
case "":
listBox.Items.Add(DateTime.Now + " " + "Pl Enter a Valid Code");
break;
case "0":
listBox.Items.Add(DateTime.Now + " " +
"Received Request - Will be there shortly");
break;
}
inputtxt.Text = "";
答案 0 :(得分:1)
为什么不向default
添加switch
案例:
default:
MessageBox.Show("Access denied");
break;