Get Key Value Pair from Enum
public static List<KeyValuePair<string, int>> GetKeyValuePairFromEnum<T>() where T : struct, IConvertible
{
List<KeyValuePair<string, int>> result = new List<KeyValuePair<string, int>>();
IEnumerable<T> array = Enum.GetValues(typeof(T)).Cast<T>();
foreach (T item in array)
{
string name = item.ToString();
int value = (int)Enum.Parse(typeof(T), name);
KeyValuePair<string, int> pair = new KeyValuePair<string, int>(name, value);
result.Add(pair);
}
return result;
}
浙公网安备 33010602011771号