小编Den*_*nny的帖子

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";  
 }
}
Run Code Online (Sandbox Code Playgroud)

我的验证功能:

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 …
Run Code Online (Sandbox Code Playgroud)

asp.net-2.0 c#-2.0

2
推荐指数
1
解决办法
2420
查看次数

标签 统计

asp.net-2.0 ×1

c#-2.0 ×1