How to traverse the content of a enumeration

xiaoxiao2021-03-06  177

Using system;

public class EnumTest {enum Days {Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday}; enum BoilingPoints {Celcius = 100, Fahrenheit = 212}; [FlagsAttribute] enum Colors {Red = 1, Green = 2, Blue = 4, YELLOW = 8};

Public static void main () {

Type weekdays = typeof (days); type boiling = typeof (boilingpoints);

Console.writeline ("The Days of the week, and their corresponding value in the day");

FOREACH (String S in Enum.Getnames (WeekDays)) Console.Writeline ("{0, -11} = {1}", s, enum.format (weekdays, enum.parse (weekdays, s), "d") );

Console.WriteLine (); Console.WriteLine ( "Enums can also be created which have values ​​that represent some meaningful amount."); Console.WriteLine ( "The BoilingPoints Enum defines the following items, and corresponding values:");

FOREACH (BOILING) Console.Writeline ("{0, -11} = {1}", S, ENUM.FORMAT (BOILING, ENUM.PARSE (BOILING, S), "D") );

Colors mycolors = colors.red | colors.blue | colors.yellow; console.writeline (); console.writeline ("Mycolors Holds a Combination of Colors. Namely: {0}", mycolors;}}

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

New Post(0)