Microsoft ASP. NET Ajax framework (8) Enumeration

Source: Internet
Author: User
Vs 2008

This document describes how to use ASP. NET Ajax core library to construct enumeration types.

1. Create an enumeration
Now I create an enumeration, indicating the nationality type. registernamespace ("Tristan ");

Tristan. Nationality = function (){
Throw error. notimplemented ();
}

Tristan. Nationality. Prototype = {
China: 1,
USA: 2,
UK: 3
}

Tristan. Nationality. registerenum ("Tristan. Nationality ");

SYS. application. policyscriptloaded ();

Steps:
1) define a function named Tristan. Nationality
2) To avoid being instantiated, an error. notimplemented () exception is thrown when the function is called.
3) Enumeration items are defined in prototype. The enumerated value must be int type.
4) register the enumeration by calling Tristan. Nationality. registerenum.

2. Test
Write the test code: // declare a variable
VaR nationality = Tristan. Nationality. USA;
SYS. Debug. Trace (nationality );
// Call tostring () method to get the Enum key
SYS. Debug. Trace (Tristan. Nationality. tostring (nationality ));
SYS. Debug. Trace (Tristan. Nationality. tostring (3 ));
// Call parse () method to get the enum Value
SYS. Debug. Trace (Tristan. Nationality. parse ("China "));

Note:
Call the tostring () method and accept a value to obtain the key of the corresponding enumeration item.
Call the parse () method and accept the key to obtain the value of the corresponding enumeration item. The key parameter is case sensitive.
Output:
2
USA
UK
1

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.