Enumeration type Summary

Source: Internet
Author: User

Enumeration
Syntax:
[Public] Enum enumeration name
{
Value 1,
Value 2
Value 3,
......
}

The enumerated type can be converted to the int type by default. The enumerated type is compatible with the int type.


Public Enum qqstate
{
Online,
Offline,
Leave,
Busy,
Qme
}

Class Program
{
Static void main (string [] ARGs)
{
Qqstate state = qqstate. online;
// The enumerated type can be converted to the int type by default. The enumerated type is compatible with the int type.
Int n = (INT) State;
Console. writeline (N );
Console. readkey ();

Int n1 = 3;
Qqstate state = (qqstate) N1; // convert int to Enum

// All types can be converted to the string type
Qqstate state = qqstate. online;
String S = state. tostring ();

// String and enumeration type conversion
Qqstate state = (qqstate) enum. parse (typeof (qqstate), "0 ");
// We can convert an enumerated type variable to the int and string types,
// The Enumeration type is compatible with the int type by default. Therefore, you can use the forced type syntax to convert each other.
// When converting a value that is not in the enumeration, the number is directly displayed instead of an exception.
// Enumeration can also be converted to the string type. If you convert the enumeration type to the string type, you can directly call tostring (),
// If you convert a string to an enumeration type, the following code is required:
// (Enumeration type to be converted) enum. parese (typeof (Enumeration type to be converted), "string to be converted ");
// If the converted string is a number, no exception is thrown even if it is not in the enumeration.
// If the converted string is text, if it is not in the enumeration, an exception is thrown.


}
}

Enumeration type Summary

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.