Enum.ToObject Method

Definition

Converts a specified integer value to an enumeration member.

Overloads

ToObject(Type, Int16)

Converts the specified 16-bit signed integer to an enumeration member.

ToObject(Type, Int32)

Converts the specified 32-bit signed integer to an enumeration member.

ToObject(Type, Int64)

Converts the specified 64-bit signed integer to an enumeration member.

ToObject(Type, Object)

Converts the specified object with an integer value to an enumeration member.

ToObject(Type, SByte)

Converts the specified 8-bit signed integer value to an enumeration member.

ToObject(Type, UInt16)

Converts the specified 16-bit unsigned integer value to an enumeration member.

ToObject(Type, UInt32)

Converts the specified 32-bit unsigned integer value to an enumeration member.

ToObject(Type, UInt64)

Converts the specified 64-bit unsigned integer value to an enumeration member.

ToObject(Type, Byte)

Converts the specified 8-bit unsigned integer to an enumeration member.

ToObject(Type, Int16)

Converts the specified 16-bit signed integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, short value);
public static object ToObject (Type enumType, short value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, short value);
static member ToObject : Type * int16 -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * int16 -> obj
Public Shared Function ToObject (enumType As Type, value As Short) As Object

Parameters

enumType
Type

The enumeration type to return.

value
Int16

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, Int16) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, Int32)

Converts the specified 32-bit signed integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, int value);
public static object ToObject (Type enumType, int value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, int value);
static member ToObject : Type * int -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * int -> obj
Public Shared Function ToObject (enumType As Type, value As Integer) As Object

Parameters

enumType
Type

The enumeration type to return.

value
Int32

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, Int32) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, Int64)

Converts the specified 64-bit signed integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, long value);
public static object ToObject (Type enumType, long value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, long value);
static member ToObject : Type * int64 -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * int64 -> obj
Public Shared Function ToObject (enumType As Type, value As Long) As Object

Parameters

enumType
Type

The enumeration type to return.

value
Int64

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, Int64) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, Object)

Converts the specified object with an integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::Object ^ value);
public static object ToObject (Type enumType, object value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, object value);
static member ToObject : Type * obj -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * obj -> obj
Public Shared Function ToObject (enumType As Type, value As Object) As Object

Parameters

enumType
Type

The enumeration type to return.

value
Object

The value convert to an enumeration member.

Returns

An enumeration object whose value is value.

Attributes

Exceptions

enumType or value is null.

enumType is not an Enum.

-or-

value is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, Object) method converts the integral value value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, SByte)

Important

This API is not CLS-compliant.

Converts the specified 8-bit signed integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::SByte value);
[System.CLSCompliant(false)]
public static object ToObject (Type enumType, sbyte value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, sbyte value);
[<System.CLSCompliant(false)>]
static member ToObject : Type * sbyte -> obj
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * sbyte -> obj
Public Shared Function ToObject (enumType As Type, value As SByte) As Object

Parameters

enumType
Type

The enumeration type to return.

value
SByte

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, SByte) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, UInt16)

Important

This API is not CLS-compliant.

Converts the specified 16-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt16 value);
[System.CLSCompliant(false)]
public static object ToObject (Type enumType, ushort value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, ushort value);
[<System.CLSCompliant(false)>]
static member ToObject : Type * uint16 -> obj
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * uint16 -> obj
Public Shared Function ToObject (enumType As Type, value As UShort) As Object

Parameters

enumType
Type

The enumeration type to return.

value
UInt16

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, UInt16) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, UInt32)

Important

This API is not CLS-compliant.

Converts the specified 32-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt32 value);
[System.CLSCompliant(false)]
public static object ToObject (Type enumType, uint value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, uint value);
[<System.CLSCompliant(false)>]
static member ToObject : Type * uint32 -> obj
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * uint32 -> obj
Public Shared Function ToObject (enumType As Type, value As UInteger) As Object

Parameters

enumType
Type

The enumeration type to return.

value
UInt32

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, UInt32) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, UInt64)

Important

This API is not CLS-compliant.

Converts the specified 64-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt64 value);
[System.CLSCompliant(false)]
public static object ToObject (Type enumType, ulong value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, ulong value);
[<System.CLSCompliant(false)>]
static member ToObject : Type * uint64 -> obj
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * uint64 -> obj
Public Shared Function ToObject (enumType As Type, value As ULong) As Object

Parameters

enumType
Type

The enumeration type to return.

value
UInt64

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, UInt64) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to

ToObject(Type, Byte)

Converts the specified 8-bit unsigned integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::Byte value);
public static object ToObject (Type enumType, byte value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, byte value);
static member ToObject : Type * byte -> obj
[<System.Runtime.InteropServices.ComVisible(true)>]
static member ToObject : Type * byte -> obj
Public Shared Function ToObject (enumType As Type, value As Byte) As Object

Parameters

enumType
Type

The enumeration type to return.

value
Byte

The value to convert to an enumeration member.

Returns

An instance of the enumeration set to value.

Attributes

Exceptions

enumType is null.

enumType is not an Enum.

.NET 8 and later versions: enumType is a Boolean-backed enumeration type.

Remarks

The ToObject(Type, Byte) method converts value to an enumeration member whose underlying value is value. Note that the conversion succeeds even if value is outside the bounds of enumType members. To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

This conversion method returns a value of type Object. You can then cast it or convert it to an object of type enumType.

See also

Applies to