Yes , Enumerations are using to define certain values as a single type and simple type. And generally class is a reference type. So stores values in heap area.
Why Enumerations:
Enumerations avoiding full bone class for a particular/Specific Constant values.
Coming to Enumerations values are stored in Stack area.
Enumerations provide good readiability.
Enumerations processes their values.
Enumerations first Element default value is zero, we can we whatever values we want. As well as no need to give values to these elements in any particular.
Enumerations stores their default values.like 0,1,2;but Enumerations Underling type is integer.
Enumerations are more helpful in developers while developing. Rather then remembering certain values.
Ex:
string[] strdays = Enum.GetNames(typeof(DayOfWeek));
foreach (string item in strdays)
{
Console.WriteLine(item);
}
int[] intdays = (int[])Enum.GetValues(typeof(DayOfWeek));
foreach (int item in intdays)
{
Console.WriteLine(item);
}
Enum is base class for all the enumerations, Enum defines few methods like Equals,GetValues,GetNames..GetUnderlyingType..ect to work with enum types.
enum is keyword to create user defined enumerations
Ex:
enum Emptype{ Admin,Staff,Employee,};
these default are zero,one,two;
enum Jobs{ Temporary =101,Parament=102,}
No comments:
Post a Comment