C # enumeration (enum)
An enumeration is a set of named integer constants. Enumeration types are declared using the enum keyword.
C # Enumerations are value data types. In other words, the enumeration contains its own values and cannot inherit or pass inheritance.
Declaring an enum variable
General syntax for declaring enumerations:
Enum <enum_name>{ enumeration list};
which
ENUM_NAME Specifies the type name of the enumeration.
The enumeration list is a comma-delimited listing of identifiers.
Each symbol in the enumeration list represents an integer value that is larger than the symbol in front of it. By default, the first enumeration symbol has a value of 0. For example:
Enum days {Sun, Mon, Tue, Wed, Thu, Fri, Sat};
Instance
The following example demonstrates the use of an enumeration variable:
Using System;namespace enumapplication{ class Enumprogram { enum days {Sun, Mon, Tue, Wed, Thu, Fri, Sat};
static void Main (string[] args) { int weekdaystart = (int) Days.mon; int weekdayend = (int) Days.fri; Console.WriteLine ("Monday: {0}", Weekdaystart); Console.WriteLine ("Friday: {0}", weekdayend); Console.readkey ();}}}
When the above code is compiled and executed, it produces the following results:
Monday:1friday:5
This is the "C # tutorial" C # enum (enum) content, more relevant content please follow topic.alibabacloud.com (www.php.cn)!