Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to use enumeration in C#
How to use enumeration in C#
Enumeration type is a value type used to declare a set of named constants.

(1) Enumeration declaration: Enumeration declaration is used to declare new enumeration types.

Access Rhetoric Enumeration Enumeration Name: Basic Type

{

Enumeration member

}

The underlying type must be able to represent all enumeration values defined in the enumeration. Enumeration declaration can explicitly declare byte, sbyte, short, ushort, int, uint, long or ulong types as corresponding base types. An enumeration declaration that does not explicitly declare the underlying type means that the corresponding underlying type is int.

(2) Enumerating members

Enumeration members are named constants of this enumeration type. No two enumeration members can have the same name. Each enumeration member has an associated constant value. The type of this value is the underlying type of the enumeration. The constant value of each enumeration member must be within the underlying type range of the enumeration. ? Example:

Public enumeration TimeofDay:uint

{

Morning =-3,

Afternoon =-2,

Night =- 1

}

A compile-time error occurred because the constant values-1, -2 and -3 are not within the range of the underlying integer uint.

(3) Enumerating the default values of members

The default value of the first enumeration member declared in an enumeration type is zero.

Subsequent enumeration member values are obtained by adding 1 to the value of the previous enumeration member (in text order). This increased value must be within the range of values that the base type can represent; Otherwise, a compile-time error will occur.