Integral to enum conversions

Enum.ToObject converts an integral value to an enum instance of the given type:


using System;
using System.Numerics;

enum WeekDay
{
    Monday, Tuesday, Wednesday, Thursday, Friday
}

class Sample
{
    public static void Main()
    {
        object bs = Enum.ToObject(typeof(WeekDay), 3);
        Console.WriteLine(bs);
    }
}

The output:


Thursday
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.