.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Enum in c#

Posted By: Deco     Posted Date: September 22, 2010    Points:2   Category :C#
What is the use of Enum?

how to implement enum

can you please get me some sample code

Responses
Author: venkat             
Posted Date: September 22, 2010     Points: 5   


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. For example:

enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};

In this enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth. Enumerators can have initializers to override the default values. For example:

enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
In this enumeration, the sequence of elements is forced to start from 1 instead of 0.

A variable of type Days can be assigned any value in the range of the underlying type; the values are not limited to the named constants.

The default value of an enum E is the value produced by the expression (E)0.

u can see this below link

http://dotnetperls.com/enum


Author: Deco             
Posted Date: September 23, 2010     Points: 5   

How to retrieve the items stored in the Enum object?

Please help.

Regards,
Deco
Author: Zinnia             
Posted Date: September 28, 2010     Points: 5   

using System;
public class flowerList
{
enum flower(Zinnia=1,Marigold,Poppy,Lotus,Hibiscus};

static void Main()
{
int a=(int)flower.Zinnia;
int b=(int)flower.Hibiscus;
Console.WriteLine("Zinnia={0}",a);
Console.WriteLine("Hibiscus={0}",b);
}
}
Output:
Zinnia=1
Hibiscus=5

Zinnia Sarkar
http://sarkarzinnia.blogspot.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend