MorkaLork Development

Interesting stuff I've picked up over the years...

Enumerations

2009-04-16 17:54:43 | 184 views | enumeration numeric constant names values

The Basics



Enumerations are basically numeric constants with usefull names. You can create a list of names with values to them, such as days of a week with a number attached to each day.

Example:



namespace TestApp
{
public enum Days {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}

class Program
{


public static void Main(string[] args)
{
Days day = Days.Monday;
Days day2 = Days.Tuesday;

Console.WriteLine("Monday has number {0} and tuesday {1}.", (int)day, (int)day2);

Console.Read();


}
}
}


This will out put "Monday has number 0 and tuesday 1."






Article comments

Feel free to comment this article using a facebook profile.

I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.