Adds a remark attribute for the enumeration (enum) type and obtains the enumerated property value.

Source: Internet
Author: User

Enumeration type (also called enumeration) is a very interesting value type. It not only improves the readability of the program, but also reduces program changes caused by business changes.

In addition, the enumeration type is strongly typed. The accept method must have the same matching parameter. Otherwise, an error will occur.

Well, let's just put it bluntly. As for the features of the enumeration type (emun), almost all programmers will understand it. I'm not doing anything here.

The following is an example, which is written on the official website by week:

 

Code
     class Program
{
static void Main(string[] args)
{

Console.Write(GetDays(Days.Saturday));
Console.Read();
}

static string GetDays(Days _days)
{
string d = string.Empty;
switch (_days)
{
case Days.Monday: d = "Today is Monday."; break;
case Days.Tuesday: d = "Today is Tuesday."; break;
case Days.Wednesday: d = "Today is Wednesday."; break;
case Days.Thursday: d = "Today is Thursday."; break;
case Days.Friday: d = "Today is Friday."; break; ;
case Days.Saturday: d = "Today is Saturday."; break;
case Days.Sunday: d = "Today is Sunday."; break;
}
return d;
}

}

public enum Days
{
/// <summary>
/// this is sunday
/// </summary>
Sunday = 7,
/// <summary>
/// this is monday
/// </summary>
Monday = 1,
/// <summary>
/// this is tuesday
/// </summary>
Tuesday = 2,
/// <summary>
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.