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

What does dbml mean in texting?

519


What is the use of flag in c#?

493


What is executescalar in c#?

464


What is yield break in c#?

510


What is a c sharp?

466






Why do you need boxing in c#?

492


How do I automate my desktop application?

505


Are structs value types c#?

475


Can hashset contain duplicates c#?

470


What are types in c#?

498


What is difference between continue and break in c#?

482


Are private members inherited in c#?

570


What's the difference between the debug class and trace class? Documentation looks the same.

508


How is a string immutable?

496


What is the advantage of singleton class?

482