public static class EnumExtension { public static string GetDescription(this Enum value) ...
根據描述獲取枚舉 lt summary gt 根據枚舉值,獲取描述 lt summary gt lt param name enumValue gt lt param gt lt returns gt lt returns gt public static string GetEnumDes Enum enumValue string value enumValue.ToString Field ...
2020-10-26 10:14 0 612 推薦指數:
public static class EnumExtension { public static string GetDescription(this Enum value) ...
C#枚舉例子: 獲取枚舉描述代碼: ...
定義枚舉: 獲取描述信息: ...
定義一個表示方向的枚舉: 獲取枚舉的描述: 使用示例: ...
1 定義枚舉: public enum Pepole { [Description("男孩")] boy=1, [Description("女孩 ...
1.首先定義一個枚舉 2.添加拓展類 3.使用方法 ...
在使用枚舉類型時,我們需要取名稱和值,甚至有時候還需要取枚舉類型的描述。通過反射,我們能獲取到枚舉類型的描述屬性。 首先我們需要給枚舉類型添加描述屬性(屬性都沒有是不可能取到的),[Description]就是描述屬性,使用這個屬性,我們需要添加 using ...
新建一個控制台方法,寫好自己的枚舉類型: 如圖: 在里面添加獲取描述的方法: 具體源碼: 鏈接:http://pan.baidu.com/s/1nv4rGkp 密碼:byz8 ...