enum type conversion

An enum value is convertable to its underline numeric value.


using System;
enum WeekDay
{
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

class Test
{
    static void Main()
    {
        int i = (int)WeekDay.Monday;

        Console.WriteLine(i);

        //We can even convert integer back to enum value.

        WeekDay day = (WeekDay)2;

        Console.WriteLine(day);
    }
}

The output:


0
Wednesday
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.