首页 > 学院 > 开发设计 > 正文

C#枚举的不常用方法Enum.Parse&Enum.GetNames

2019-11-17 04:18:07
字体:
来源:转载
供稿:网友

public enum OpType  
{  
  Addnew,  
  Update,  
  Delete  

public enum OpType
{
  Addnew,
  Update,
  Delete
}  

1.根据枚举列表名字字串取得对应的值。

string opStr = "Delete";  
int result = (int)Enum.Parse(typeof(OpType), opStr); 
string opStr = "Delete";
int result = (int)Enum.Parse(typeof(OpType), opStr);
 

2.将枚举转换为数组。

Enum.GetNames(typeof(OpType))


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表