Convert Enum to Dictionary for binding
Posted on: Thu Dec 09 11:46:41 -0800 2010. Updated on: Thu Dec 09 11:48:25 -0800 2010.
Category: .NET C#
Category: .NET C#
Sometimes we need to bind an enum to a dropdown or something of the sort. Sometimes we want to join in a linq query. The best way to do this is to convert the Enum to a typed Dictionary
public static class Utilities
{
public static Dictionary ConvertToDictionary(Type enumType)
{
// get the names and values from the enumeration
List names = Enum.GetNames(enumType).ToList();
Array values = Enum.GetValues(enumType);
Dictionary dict = new Dictionary();
for (int i = 0; i < names.Count; i++)
dict.Add((int)values.GetValue(i), names[i]);
return dict;
}
}
Mon Jan 03 02:39:33 -0800 2011
If you are in a not good position and have no money to go out from that point, you will need to take the <a href="http://bestfinance-blog.com">loan</a>. Because it will help you definitely. I take car loan every single year and feel OK because of it.
---------------------------------------------------