Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C # enumerated types

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report