惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
小众软件
小众软件
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
博客园_首页
G
Google Developers Blog

博客园 - StephenJu

EntLib--Unity Application Block 1.x DevExpress杂项 .Net异步机制 简单的异步调用 按s1_Name+uuid为一组拆分DS 分割dataset:待改进... 序列化 DataGridViewComboBoxColumn的使用 datagridview数据验证 通过关键字查找到dgv相关记录后定位 禁止一个程序启动多个实例 将文本文件的内容写进某个表中 获取Assembly的运行路径 获取ArrayList中的数据(foreach) 关于DataTable里大批量查找的更快速的方法 抽象类 IO DynamicCreateMenu DataTable的简单方法
枚举
StephenJu · 2008-12-26 · via 博客园 - StephenJu

public enum EnumName //tt:枚举名
        {
            [Description(
"t1描述")]//枚举标记t1的描述
            t1=1,//t1:枚举标记 1:枚举值
            [Description("t2描述")]
            t2
=2,
            [Description(
"t3描述")]
            t3
=3
        }
private string GetEnumDescription(Enum enumValue)
        {

            FieldInfo fieldInfo 

= enumValue.GetType().GetField(enumValue.ToString().Trim());
            DescriptionAttribute[] attritutes 
= fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), falseas DescriptionAttribute[];
            
return attritutes.Length > 0 ? attritutes[0].Description: enumValue.ToString();
        }
//根据枚举标记获得枚举值
            int iEnumValue = (int)Enum.Parse(typeof(EnumName), Convert.ToString(EnumName.t1));
//result:1
            
//根据枚举值得到枚举标记
            EnumName t_type = (EnumName)Enum.Parse(typeof(EnumName), Convert.ToString(iEnumValue), false);
//result:t1
            
//根据枚举标记获得其描述
            string strDescription = GetEnumDescription(t_type);
//result:t1描述