codescracker


c#

C# Enum



« Previous Tutorial Next Tutorial »


An enumeration is simply a set of named integer constants. You can declare enumeration in C# programming, just by using the keyword enum.

C# enum Variable Declaration

Here is the general form to declare an enum variable in C# programming:

enum enum-name {enumeration-list};

Here is an example, declaring enumeration in C#:

enum Weeksday{Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};

C# enum Example

Here is an example program, illustrates the concept and use of enum in C#:

/* C# enum - Example Program */
		
using System;
namespace EnumExample
{
	class EnumClass
	{
		enum Weeksday{Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
		
		static void Main(string[] args)
		{
			int weekstart = (int)Days.Monday;
			int weekend = (int)Days.Saturday;
			Console.WriteLine("Monday = {0}", weekstart);
			Console.WriteLine("Saturday = {0}", weekend);
			Console.ReadKey();
		}
	}
}

When we compile and run the above program, it will produce the following output:

Monday = 1
Saturday = 6

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test