Summary of the use of enumeration types in C #

Source: Internet
Author: User

Resolution:
It is a user-declared value type.

Sample Code:
Enum Suit
{
Clubs, Diamonds, Hearts, Spades
}
// Suit indicates a deck, which has four colors: plum blossom (Clubs), Diamonds, Hearts, // Spades)
Sealed class Example
{
Static void Main ()
{
...
Suit lead = Spades; // Error
...
Suit trumps = Suit. Clubs; // correct
...
}
}

Rules:
The enumeration declaration can appear in the same place as the class declaration.
The declaration of enumeration includes the name, access permission, internal type, and enumeration member.
The range of constants declared in enumeration is to define their enumeration. In other words, the following example is incorrect:
Suit trumps = Clubs;
Clubs must be limited to a Suit member, as shown below:
Suit trumps = Suit. Clubs;


Author: ershouyage

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.