C# Enum ToObject(Type, Object)

Description

Enum ToObject(Type, Object) converts the specified object with an integer value to an enumeration member.

Syntax

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


[ComVisibleAttribute(true)]/*from w  w  w  .j av a  2  s .c o m*/
public static Object ToObject(
  Type enumType,
  Object value
)

Parameters

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

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

Returns

Enum.ToObject(Type, Object) method returns An enumeration object whose value is value.

Example


/*from www  .  j a v  a2 s  .co  m*/
using System;
enum Mammals { Cat, Dog, Horse, Dolphin };

public class MainClass{
  public static void Main(String[] argv){  
    
    Object obj = Enum.ToObject(Mammals.Cat.GetType(),0);
    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