C# Enum ToObject(Type, Int32)

Description

Enum ToObject(Type, Int32) converts the specified 32-bit signed integer to an enumeration member.

Syntax

Enum.ToObject(Type, Int32) has the following syntax.


[ComVisibleAttribute(true)]/*from ww  w .  j a  v a  2s.com*/
public static Object ToObject(
  Type enumType,
  int value
)

Parameters

Enum.ToObject(Type, Int32) has the following parameters.

  • enumType - The enumeration type to return.
  • value - The value to convert to an enumeration member.

Returns

Enum.ToObject(Type, Int32) method returns An instance of the enumeration set to value.

Example


/*from w ww  .ja  v a 2  s  . c om*/

using System;

enum Mammals { Cat, Dog, Horse, Dolphin };
public class MainClass
{
    public static void Main(String[] argv)
    {

        Object obj = Enum.ToObject(Mammals.Cat.GetType(), 1);
        Console.WriteLine(obj);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version