The significance of enumeration is to limit the value range of variables.
It can be used only when several values can be determined.
If you enter a string to determine whether it is a string we need, you generally need to write it like this:
Using system; using system. collections. generic; using system. text; namespace enumeration learning {class program {static void main (string [] ARGs) {string S = "male"; if (S = "male") {console. writeline ("male");} else if (S = "female") {console. writeline ("female");} else if (S = "unknown") {console. writeline ("unknown");} else {console. writeline ("illegal input");} console. readkey ();}}}
However, it seems too troublesome to write data in this way. In this case, you can simply use the enumeration type to solve the problem. The Code is as follows:
Using system; using system. Collections. Generic; using system. Text; // The significance of enumeration is to limit the value range of variables. It can be used only when there are several definite values. Namespace enumeration learning {Enum gender {male, female, unknown}; // class program {static void main (string [] ARGs) {gender S = gender. female; // The value options of the variable include male, female, and unknown. Console. writeline (s); // print the results female console. readkey ();}}}