Experience Summary 40--c# Enumeration

Source: Internet
Author: User

Enumeration, typically used to customize some static variables, with keys and values.

such as Audit status:

public enum enumstate{

Pending review = 1, technology audited = 2, financial audited = 3, Mister Audited =4

}

This allows you to use enumerations for code operations instead of using strings.

Get string: enumstate. Technology has been audited. ToString ()

Get value: (int) enumstate. Technology audited

Binding in HTML. Loop Enumeration

@foreach (var name in Enum.getnames (typeof (Enumstate)))
{
int key = (int) (enumstate) Enum.parse (typeof (Enumstate), name);//Get enumeration by value
<option value= "@key" > @name </option>
}

However, enumerations cannot be string switch, as long as int is judged.

Enumstate State;

Switch (state) {

case (int) enumstate. Technology has been audited:

Break

}

The greatest benefit of using enumerations is that the enumeration is modified, and the other places are modified to ensure consistency and ease of use.

Experience Summary 40--c# Enumeration

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.