Explicit enumeration conversions for C #

Source: Internet
Author: User

An explicit enumeration transformation includes the following:

From sbye,byte,short,ushort,int,uint,long,ulong,char,float,double, or decimal, to any enumeration type.

From any enumerated type to sbyte,byte,short,ushort,int,uint,long,ulong,char,float,double, or decimal.

From any enumerated type to any other enumeration type.

An explicit enumeration transformation is done in this way: it is actually an implicit or explicit conversion between the element type of an enumerated type and the corresponding type. For example, there is an enum type E with the element type int, when you perform an explicit enumeration conversion from E to Byte, you actually do an explicit numeric conversion from int to Byte, and when you perform an explicit enumeration conversion from byte to E, you are actually performing an implicit numeric conversion of byte through int.

For example, for program 6-2, we rewrite the following:

Program Listing 6-7:

Using System;

Enum weekday{
   sunday,monday,tuesday,wednesday,thursday,friday,saturday
};

Class Test

{public
  static void Main () {
     weekday day;
     Day= (weekday) 3;
     Console.WriteLine (day);
  }

The output of the program is:

3

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.