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.
解决方案City[] values = (City[])Enum.GetValues(typeof(City));
var valuesWithNames = from value in values
select new { value = (int)value, name = value.ToString() };