Enumeration
Syntax:
[Public] Enum enumeration name
{
Value 1,
Value 2
Value 3,
......
}
The enumerated type can be converted to the int type by default. The enumerated type is compatible with the int type.
Public Enum qqstate
{
Online,
Offline,
Leave,
Busy,
Qme
}
Class Program
{
Static void main (string [] ARGs)
{
Qqstate state = qqstate. online;
// The enumerated type can be converted to the int type by default. The enumerated type is compatible with the int type.
Int n = (INT) State;
Console. writeline (N );
Console. readkey ();
Int n1 = 3;
Qqstate state = (qqstate) N1; // convert int to Enum
// All types can be converted to the string type
Qqstate state = qqstate. online;
String S = state. tostring ();
// String and enumeration type conversion
Qqstate state = (qqstate) enum. parse (typeof (qqstate), "0 ");
// We can convert an enumerated type variable to the int and string types,
// The Enumeration type is compatible with the int type by default. Therefore, you can use the forced type syntax to convert each other.
// When converting a value that is not in the enumeration, the number is directly displayed instead of an exception.
// Enumeration can also be converted to the string type. If you convert the enumeration type to the string type, you can directly call tostring (),
// If you convert a string to an enumeration type, the following code is required:
// (Enumeration type to be converted) enum. parese (typeof (Enumeration type to be converted), "string to be converted ");
// If the converted string is a number, no exception is thrown even if it is not in the enumeration.
// If the converted string is text, if it is not in the enumeration, an exception is thrown.
}
}
Enumeration type Summary