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
Explain the term inheritance in C#.
What are the advantages of using delegates in c#?
How long can a string be c#?
What is the base class from which all value types are derived?
Is c++ or c# better?
Are c# strings null terminated?
What is unmannaged code and will CLR handle this kind of code or not .
What is .cs file in c#?
How many bytes is an int c#?
What is data binding c#?
Explain the difference between a struct and a class?
What is difference between ienumerable and list in c#?
What is serialization in .net?
What's the implicit name of the parameter that gets passed into the set method/property of a class?
Which one is trusted and which one is untrusted?