C # enumeration (Enum) usage and Traversal method

Source: Internet
Author: User
Tags comparison table
Foreach ( String S In Enum. getnames ( Typeof (Wallkind )))
{
Winformtools. msgbox (s );
}

Someone asked how to traverse the enumeration in revit API. traversing enumeration is the syntax function of C. From msdn
Enumeration can be used to store value pairs of strings and numbers, which is equivalent to a comparison table.
Common Methods: getname (), getvalue (), parse ()
Using System;

Public Class Enumtest {
Enum Days {Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
Enum Boilingpoints {Celcius = 100 , Fahrenheit = 212 };
[Flagsattribute]
Enum Colors {Red = 1 , Green = 2 , Blue = 4 , Yellow = 8 };

Public Static Void Main (){

Type weekdays = Typeof (Days );
Type boiling = Typeof (Boilingpoints );

Console. writeline ( " The days of the week, and their corresponding values in the days Enum are: " );

Foreach ( String S In Enum. getnames (Weekdays ))
Console. writeline ( " {0,-11 }={ 1} " , S, enum. Format (weekdays, enum. parse (weekdays, S ), " D " ));

Console. writeline ();
Console. writeline ( " Enums can also be created which have values that represent some meaningful amount. " );
Console. writeline ( " The boilingpoints Enum defines the following items, and corresponding values: " );

Foreach ( String S In Enum. getnames (boiling ))
Console. writeline ( " {0,-11 }={ 1} " , S, enum. Format (boiling, enum. parse (boiling, S ), " D " ));

Colors mycolors = colors. Red | colors. Blue | colors. Yellow;
Console. writeline ();
Console. writeline ( " Mycolors holds a combination of colors. Namely: {0} " , Mycolors );
}
}

URL: http://greatverve.cnblogs.com/archive/2012/06/06/Enum.html

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.