Possible Duplicate:
IEnumerable Extension Methods on an Enum
How can I use Generics to create a way of making an IEnumerable from an enum?
Given enums like this:
public enum City
{
London = 1,
Liverpool = 20,
Leeds = 25
}
public enum House
{
OneFloor = 1,
TwoFloors = 2
}
How can I convert these into an IEnumerable lists with two fields named “data” and “value”. Would it be possible to have a generic method or way of doing this? Please not that the values are not always sequential.
You can use
Enum.GetValues: