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
Is xml tags are case sensitive?
What is using keyword?
Explain the difference between a Private Assembly and a Shared Assembly
Explain About multi level and multiple inheritance how to achieve in .net
What are examples of desktop applications?
Why singleton pattern is used in c#?
Can var be null c#?
Name the control which cannot be placed in mdi?
What are the different ways of method can be overloaded?
Illustrate race condition?
How do I declare a pure virtual function in c#?
If you donot specify an access modifier for a method, what is the default access modifier?
How to implement singleton design pattern in c#?
Define property in c#.net?
Explain what a diffgram, and a good use for one Define diffgram? How it be used?