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 ildasm.exe used for?
How does a while loop work?
What is stringreader in c#?
Name any three ways to pass parameters to a method in c#?
Explain About Iunknown interface Queue
Can struct inherit from class c#?
Can abstract classes be final?
Define multicast delegate in c#?
how to sort an array in c#
Is a char?
Are c# constructors the same as c++ constructors?
What are the fundamental differences between value types and reference types?
What is the delegates in c#?
How many keyword present in C# language ?
Can hashtable have duplicate keys in c#?