C # description and use of enumeration types [important description]

Source: Internet
Author: User

1. technical definitions of enumeration:

[Nature] [modifier] enum identifier [: base type] {enumeration list };

2. Common examples: (separated by commas)

[Csharp]
Enum Temperatures
{
SMALL,
LARGE = 5
}


Note:
1. The default base type is int, but ushort and long can be used at will, except for char. The data is a constant and cannot be changed. The preceding example is equivalent to const int SMALL = 0.
2. to display the value of an enumerated constant, You need to convert the constant to its underlying type. The above example should be converted to the int type.
3. Each constant in the enumeration corresponds to a value. The preceding example is an integer. If this parameter is not set, the enumeration starts from 0, and the next one is the first one plus 1. The above SMALL is 0, and LARGE is 5.
4. The conversion between the enumerated type and the integer type needs to be performed explicitly.
5. In C ++, the enumerated type must be assigned an integer, but the promote can be used as an integer to assign a value to the integer.
6. The base types include byte, sbyte, short, ushort, int, uint, long, And ulong.

3. Example:

[Csharp]
System. Console. WriteLine ("display SMALL value: {0}", (int) Temperatures. SMALL );

This article aims to popularize knowledge. If you find it helpful,
Please click the top word below to show more startup programmers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.