我有一个用于输入验证的标志枚举列表,我想返回其中一个枚举作为验证的一部分。到目前为止,这就是我想出的……
这些是我的枚举。
[Flags]
public enum CheckInput
{
Not_Valid,
OK,
No_First_Name,
No_Last_Name,
No_Password,
Wrong_Password
};
这是我在使用枚举时显示消息的开关
public void ValidInputSwitch()
{
CheckInput Status = CheckInput.Not_Valid;
do
{
switch (Status)
{
case CheckInput.No_First_Name:
MessageBox.Show("Please enter your first name.");
break;
case CheckInput.No_Last_Name:
MessageBox.Show("Please enter your last name.");
break;
case CheckInput.No_Password:
MessageBox.Show("Please enter your password.");
break;
case CheckInput.Wrong_Password:
MessageBox.Show("Your passwords do not match!");
break;
case CheckInput.OK:
CheckUserName(Uname);
break;
default:
break;
}
}
while (Status != CheckInput.OK);
}
这是我的问题所在,我想验证输入并返回枚举,以便它可以与我的开关一起运行并显示那里的消息
public CheckInput InputCheck
{
{
if (firstNameTxt.Text == null || firstNameTxt.Text == "") { return CheckInput.No_First_Name; }
}
}
我实际上最终放弃了这个想法并使用了“错误报告”。我不能完全让这种方法为我工作。肯定是因为我不知道怎么做。有一天,我希望能解决我遇到的问题。