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
What does dbml mean in texting?
What is the use of flag in c#?
What is executescalar in c#?
What is yield break in c#?
What is a c sharp?
Why do you need boxing in c#?
How do I automate my desktop application?
Are structs value types c#?
Can hashset contain duplicates c#?
What are types in c#?
What is difference between continue and break in c#?
Are private members inherited in c#?
What's the difference between the debug class and trace class? Documentation looks the same.
How is a string immutable?
What is the advantage of singleton class?