您的位置:首页 > 编程语言 > C#

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

2011-07-21 16:00 267 查看
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))(王朝网络 wangchao.net.cn)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: