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 xml comments in c#?
Explain About DTS package
Name some string escape sequences in c#.
What is the difference between first and firstordefault?
How to rotate an Image in C#?
Explain how obfuscator works in .net
Why do we use partial class in c#?
How many digits are in an integer?
What is ilasm.exe used for?
What are Uses of CLR
What is the delegates in c#?
Explain how to implement an object pool in c#.net
What is a Managed Code??
What is hashset c#?
What is sqlcommandbuilder c#?