C#枚举遍历及获取描述

yourenum 需要遍历的枚举

private void _enum_foreach()
    {
        foreach (yourenum r in Enum.GetValues(typeof(yourenum)))
        {
            FieldInfo f = r.GetType().GetField(r.ToString());

            DescriptionAttribute arr = System.Attribute.GetCustomAttribute(f, typeof(DescriptionAttribute)) as DescriptionAttribute;

            int _value = (int)r;
            string _key = r.ToString();
            string _name = arr.Description;

            Response.Write(string.Format("{0}:{1}____{2}
", _value, _key, _name)); } }

你可能感兴趣的:(C#,c#)