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 is collection of classes in c#?
Enlist some of the properties of a thread class?
How objects are stored in memory?
What are the fundamental differences between value types and reference types?
Explain when should you call the garbage collector in .net?
What does an indexer do?
Can constructor be protected in c#?
What is difference between array and arraylist c#?
What is int32 in c#?
What do you mean by object pooling?
What Is A Multicast Delegate?
Can you store different types in an array in c#?
Explain About CLS?
What will be the output of the following code?
What to implement on my class Finalize or IDisposable