Powered by Blogger.

Saturday, March 8, 2014

Enum in C#.Net



In this article we will discuss about Enum in C#.Net.

Also you can check out:

- Caching in Asp.Net

- Read and write from Text file in Asp.Net

- How to handle exception in sql server stored procedure?

- The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.

-  we can declare like below:

enum WesiteList
{
AspDotNetHelp,
Fewlines4Biju,
OnlySharePoint2013,
SharePoint_Net,
EnjoySharePoint
}

Here in this enumeration AspDotNetHelp is o, Fewlines4Biju is 1 etc.

- But you can initialize enumeration like below:

enum WesiteList
{
AspDotNetHelp=1,
Fewlines4Biju,
OnlySharePoint2013,
SharePoint_Net,
EnjoySharePoint
}

Here in this enumeration AspDotNetHelp is 1, Fewlines4Biju is 2 etc.

We can get the value like below:

int website = (int) WebsiteList.AspDotNetHelp;

- .Net class library uses Enumeration hugly.

- Enums are value types and are created on the stack and not on the heap.



0 comments

Post a Comment