[Microsoft Techies Blog] Defining Enumeration Types in console application

2 views
Skip to first unread message

Amit thakur

unread,
Dec 6, 2011, 11:49:19 AM12/6/11
to techie...@googlegroups.com
An enumeration is a user-defined value type that inherits directly from the System.Enumtype. You typically use enumeration types to represent a fixed set of options such as the days of the week or the possible states of a database connection. To define an enumeration type, use the enum (C#) keyword. An
Enumeration type contains mnemonics that represent integer values; these values start at 0 and increase in steps of 1 by default. Enumerations cannot define methods, properties, or constructors. Furthermore, enumerations cannot implement interfaces, and they cannot explicitly inherit from a class or be used as a base class.

The following examples shown:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
enum color { red, green, blue,white,black,orange,pink,yellow, };

class Program
{
static void Main(string[] args)
{
Console.WriteLine((int)color.red);
Console.WriteLine((int)color.green);
Console.WriteLine((int)color.blue);
Console.WriteLine((int)color.white);
Console.WriteLine((int)color.black);
Console.WriteLine((int)color.orange);
Console.WriteLine((int)color.pink);
Console.WriteLine((int)color.yellow);

Console.ReadLine();
}
}
}

Output is display bellow.



--
Posted By Amit thakur to Microsoft Techies Blog at 12/06/2011 08:49:00 AM
Reply all
Reply to author
Forward
0 new messages