Examples of C # traversing enum types in asp.net

Source: Internet
Author: User

for enum type
:
Use foreach to traverse the elements of the enum type and populate the Combox

The code is as follows Copy Code

foreach (Hatchstyle hs1 in Enum.getvalues (typeof (Hatchstyle)))
{
COMBOBOX1.ITEMS.ADD (HS1. ToString ());
}

Example

  code is as follows copy code

public enum Beeptype
{
Simplebeep =-1,
Iconasterisk = 0x00000040,
Iconexclamation = 0x00000030,
Iconhand = 0x0000 0010,
Iconquestion = 0x00000020,
Ok = 0x00000000,
       }
string[] x = (string[]) Enum.getnames (typeof (Win32api.beeptype));
int[] y = (int[]) enum.getvalues (typeof (Win32api.beeptype));
for (int i = 0; i < i++)
{
    MessageBox.Show (i.ToString ());
    W In32api.messagebeep ((Win32api.beeptype) i);
}

Enumeration can be used to store the value pairs of strings and numbers, which is equivalent to a comparison table
Common methods: GetName (), GetValue (), Parse ()

The code is as follows Copy Code

Using System;

public class Enumtest {
Enum days {Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday};
Enum Boilingpoints {Celcius = +, 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" of 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.");
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);
}
}

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.