Enumerate

zhaozj2021-02-16  60

Enumeration is a very interesting structure. In .NET, the enumeration type holds some cool features. The type of enumeration is taken as an example: Enum accessright: int // Access permission for some resource {read = 1, // Read hexadecimal 0x01 Write = 2, // Write hexadecimal 0x02 delete = 4 // Delete hexadecimal 0x04} In .NET, we can: Accessright Right = Accessright.read; // Get enumeration Variable Right The decimal of the value indicates String S1 = Right.Tostring ("D"); / / Gets the hexadecimal of the value of the enumerated variable Right represents String S2 = Right.toString ("x"); // Get an enumeration variable Right's enumeration name, here is ReadString S3 = Right.toString ("g"); if you think the above assignment statement: (Accessright Right = Accessright.Read;) is not flexible enough, you can use: // Use Raise a enumeration ACCESSRIGHT Right = (Accessright) system.enum.parse (TypeOf (Accessright), "Read"); / / can also be used to get an enumeration value to get an enumeration acceptright right = (accessright) system. ENUM.PARSE (TypeOf (Accessright), "1"); in addition, you can also traverse an enumeration type FOREACH (Accessright Right ") system.enum.getvalues ​​(TypeOf (accessright))) {} final, You can also perform an algorithm an algorithm accessright.read | accessright.write; string ss = right.toString ("f"); then SS will be "read, write"

转载请注明原文地址:https://www.9cbs.com/read-19019.html

New Post(0)