Enumerations in C#
Enumerations are types that inherit from System.Enum. The elements of an enumeration are expressed in words rather than numbers, which makes it convenient for understanding the meaning of the value being used. Enumerations symbolically represent a set of values of one of the primitive integral types. The type of the elements of an enumeration can be byte, short, int or long. If no type is specified explicitly, the default type is int.
public enum Categories
{
Burgers = 1,
Desserts = 2,
DrinkXSpecials = 3,
FromXtheXGrills = 4,
HappyXHour = 5,
KidsXMenu = 6,
LunchXSpecials = 7,
PartyXMenu = 8,
Salads = 9,
Sandwiches = 10,
Seafood_XPastasXandXmore = 11,
Soups = 12,
}
public class UserEnum
{
public static void Main()
{
int c1 = (int)Categories.Burgers;
int c2 = (int)Categories.KidsXMenu;
Console.WriteLine(c1 + " " + c2 );
}
}
public enum Categories
{
Burgers = 1,
Desserts = 2,
DrinkXSpecials = 3,
FromXtheXGrills = 4,
HappyXHour = 5,
KidsXMenu = 6,
LunchXSpecials = 7,
PartyXMenu = 8,
Salads = 9,
Sandwiches = 10,
Seafood_XPastasXandXmore = 11,
Soups = 12,
}
public class UserEnum
{
public static void Main()
{
int c1 = (int)Categories.Burgers;
int c2 = (int)Categories.KidsXMenu;
Console.WriteLine(c1 + " " + c2 );
}
}
No comments:
Post a Comment