Friday, May 16, 2014

Enumeration

    An Enumeration is used to store pre-defined values.

It is not a data structure. An Enumeration is derived from  System.Enum structure.

public enum  MyValues  // : int
{
Value1, // 0
Value2 = 100,
Value3, // 101
Value4, // 102
}

Default Data Type of an enum is 'int'.

public enum  MyColors : short {
Red, // 0
Green, // 1
Yellow, // 2
Blue // 3
}
------------------------------------------------------------------------------------------------
Data Types supported in an enumeration are:
byte, sbyte,
short, ushort,
int[default], uint,
long, ulong.

Char type is NOT supported.

MyValues.Value1 // Value1
(int) MyValues.Value1 // 0

MyColors.Red // Red
(short) MyColors.Red // 0


Enumeration in .NET Class Library:

TextBoxMode  enum // TextBox
RepeatDirection  enum // DataList, RadioButtonList, CheckBoxList

SqlDbType  enum
CommandType  enum
CommandBehavior  enum

----------------------------------------------------------------------------------------------

if((short)MyColors.Red == 0){
LblMsg.ForeColor = Color.Red;
}

No comments :

Post a Comment