Search This Blog

Monday, January 26, 2009

Enumerating an enum

Here's a very simple way to enumerate an enumeration:


enum UserAttributes {alias, cn, co, companyname, country, displayname}
foreach (UserAttributes enumValue in Enum.GetValues(typeof(UserAttributes)))
{
Console.WriteLine(enumValue.ToString());
}


I use enums a lot with command-line utilities and this is useful for putting together a cleaner, smaller "displaySyntax" function.

No comments: