What is ENUM?

Answer Posted / srinivasan

Enum is a type for which the memory will be allocated on the stack instead of the heap. It can be used to write presentable code in place where we will be using integers. For Ex.

Enum Declaration

private Enum OperationalResult
{
Success = 1,
Failure = 2
}

Enum Usage

Switch (result)
{
case: (int)OperationalResult.Success
MessageBox.Show("Yippe,Operation Success");
break;
case: (int)OperationalResult.Failure
MessageBox.Show("OOPS! It's a failure");
break;
default:
MessageBox.Show("OOPS! Canno determine");
break;
}

Here in the above code, if the following statement
(int)OperationalResult.Success is replaced with 1, it does not make sense and a new developer looking at the wouldn't understand what 1 represents.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the term inheritance in C#.

532


What are the advantages of using delegates in c#?

462


How long can a string be c#?

505


What is the base class from which all value types are derived?

493


Is c++ or c# better?

535






Are c# strings null terminated?

527


What is unmannaged code and will CLR handle this kind of code or not .

583


What is .cs file in c#?

515


How many bytes is an int c#?

486


What is data binding c#?

519


Explain the difference between a struct and a class?

492


What is difference between ienumerable and list in c#?

439


What is serialization in .net?

558


What's the implicit name of the parameter that gets passed into the set method/property of a class?

584


Which one is trusted and which one is untrusted?

506