以下代碼總是按enum
的值排序,但我想按位置排列在enum
之間。您注意到Matchup
在enum
中排名第三,但值爲6.它總是作爲列表中的最後一次出現在迭代中。在枚舉中創建枚舉列表,並且不包含值
foreach (var enumName in Enum.GetValues(enumType).Cast<TEnum>())
{
}
public enum RestrictionDetailType
{
[EnumMember(Value = "0"), Display(Name = "None")]
None = 0,
[EnumMember(Value = "1"), Display(Name = "Team")]
Team = 1,
[EnumMember(Value = "6"), Display(Name = "Matchup")]
Matchup = 6,
[EnumMember(Value = "2"), Display(Name = "Date/Time")]
DateTime = 2,
[EnumMember(Value = "3"), Display(Name = "Venue")]
VenueCourt = 3,
[EnumMember(Value = "4"), Display(Name = "Games")]
Games = 4,
[EnumMember(Value = "5"), Display(Name = "Exhibition")]
Exhibition = 5
}
你可以做任何順序它們的數組列表,你想和使用相反。 – juharr
或者,在枚舉中創建一個新的屬性來存儲顯示順序和順序。 –
@DiskJunky - 呃? ['GetValues()'](https://msdn.microsoft.com/en-us/library/system.enum.getvalues(v = vs.110).aspx)被記錄爲返回它們的順序「由其無符號的大小「 –