存在我宣布我的C#应用程序常数是这样的:C#校验值在不断
public class Constant
public struct profession
{
public const string STUDENT = "Student";
public const string WORKING_PROFESSIONAL = "Working Professional";
public const string OTHERS = "Others";
}
public struct gender
{
public const string MALE = "M";
public const string FEMALE = "F";
}
}
我的验证功能:
public static bool isWithinAllowedSelection(string strValueToCheck, object constantClass)
{
//convert object to struct
//loop thru all const in struct
//if strValueToCheck matches any of the value in struct, return true
//end of loop
//return false
}
在运行时,我会想在用户输入的值传递和该结构检查结构中是否存在该值。结构可以是职业和性别。我怎样才能实现它?
例子:
if(!isWithinAllowedSelection(strInput,Constant.profession)){
response.write("invalid profession");
}
if(!isWithinAllowedSelection(strInput,Constant.gender)){
response.write("invalid gender");
}
这听起来像一个'enum'比结构更好的情况。 – RPM1984 2010-10-21 10:09:18