How to use C # enumerated types
This article introduces the relevant knowledge of "how to use C# enumeration types". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
C # enumeration, an enumeration is a value type that consists of constants with many names (also known as enumeration tables). For example
Const int Monday=0; const int Tuesday=1;... Const Sunday=7
You can enumerate types with C #
Enum Week {Monday,Tuesday, Wednesday, Thursday,Friday,Saturday,Sunday}
Each constant in the C # enumeration corresponds to a numeric value, and if not specifically set, the enumeration starts at 0, and each subsequent value adds 1 to the previous value. If there are the following definitions
Enum Values {value1, value2, vlaue3=30, value4}
Among them, value1=0,value2=1,value3=30,value4=31
It is important to note that the conversion between C# enumerated types and integers needs to be displayed:
Int a = (int) Week.Friday
Example of C# enumerated types:
Public class food {public enum foodType {Pizza=1,Pasta,Spaghetti} public void GetFoodOrder (string Custname, foodType order) {Console.WriteLine ("the dinner of customer {0} is {1}", Custname,order);}} / / C# enumeration type class Program {static void Main (string args) {food myfood = new food (); myfood.GetFoodOrder ("Scoopy", (food.foodType.Pizza)) Console.WriteLine ("you are enjoying our" + (int) food.foodType.Pizza+ "staple food"); Console.ReadLine ();}}
The running result of the instance of C# enumerated type is
This is the end of the content of "how to use C# enumerated types". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!