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;
            }

              }
  • 相关阅读:
    Shell编程学习1-变量的高级用法
    Ubuntu新机配置深度学习环境遇到的问题
    Python细致技巧总结(不断更新)
    图片着色后存储为“JPEG”格式存在明显色差问题解决
    python图片合成视频
    caffe-ssd安装问题解决
    python画图
    python split(),os.path.split()和os.path.splitext()函数用法
    转载:mysql 存储过程
    css实现div框阴影
  • 原文地址:https://www.cnblogs.com/buaaboyi/p/1931921.html
Copyright © 2011-2022 走看看