Enum is for Enumeration
Category: DotNet
Enumerators can come in handy anyplace where you need a list of items that could be passed in as parameters. This way you avoid using a string or an integer that could get messed up and cause a run time error. Declared enums provide intellisense in VS so they are quick to code too.
An example would be user types or groups, ie Admin, public, editor, etc.
In many cases it is better to have types databound to sql database but for simpler things an enum will do.
public enum Groups
{
Unknown = 0,
admin = 1,
editor = 2,
everyone = 3
}
int admin = (int)Groups.admin;
// the above would return integer with value 1
Groups group = (Groups)2;
// the above would return enum Group object with "editor" option selected.
Note that I define the integer value of each item and start with Unknown = 0. There is a bug that causes an enum not to travel well through web services. So, if you are declaring an enum in a web service and want to access it on the client, be sure to start with 0.
To bind an enum to a dropdown box or other datasource, this guy has a good article that works: http://www.developerfusion.com/code/4713/binding-a-control-to-an-enum/