Wednesday, May 27, 2009

Enumerating enum

Probably all of us have encountered the situation where we need to enumerating a enum type. For example, we may want to put all the enum values in a listbox. The solution may not be so straight forward to come up with, but is simple enough: (RegistryValueKind is an enum type in Microsoft.Win32 namespace)

List<string> list = new List<string>();

foreach( RegistryValueKind kind in




list.Add(kind.ToString() + ((int)kind).ToString());


No comments: