zoukankan      html  css  js  c++  java
  • 枚举到整型的转换,扩展方法为枚举添加方法取得整数值

    枚举到整型的转换,扩展方法为枚举添加方法取得整数值

    代码
        public enum OperateTypeEnum
        {
            Add 
    =1,//添加
            Edit=2,//修改,编辑
            Delete = 3,//
           
            
        }

        
        
    public static class EnumHelp
        {
            
    public static int GetValue(this OperateTypeEnum operateTypeEnum)
            {
                Type type 
    = operateTypeEnum.GetType();
                List
    < KeyValuePair<int,OperateTypeEnum>> keyCodeList = (from s in Enum.GetNames(type)
                                                                        let keyCode 
    = Int32.Parse(Enum.Format(type, Enum.Parse(type, s), "d"))
                                                                        let operateType 
    = (OperateTypeEnum) Enum.Parse(type, s)
                                                                        select 
    new KeyValuePair<int, OperateTypeEnum>(keyCode, operateType)).ToList();
                KeyValuePair
    <int, OperateTypeEnum> currenItem = keyCodeList.FirstOrDefault(obj => obj.Value == operateTypeEnum);

                
    return currenItem.Key;
            }

              }
  • 相关阅读:
    鼠标滑过,解决ul下 li下a的背景与父级Li不同宽的问题
    php函数
    常用函数之数组函数
    php流程控制
    php运算符
    php常量
    php变量的数据类型
    PHP是什么
    css3新增属性
    html5的常用标签
  • 原文地址:https://www.cnblogs.com/buaaboyi/p/1931921.html
Copyright © 2011-2022 走看看