C # Tutorial C # enumeration (enum)

Source: Internet
Author: User

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)!

  • 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.