Enum.ToObject 方法

定義

將指定的整數值轉換為列舉成員。Converts a specified integer value to an enumeration member.

多載

ToObject(Type, Int16)

將指定的 16 位元帶正負號的整數轉換為列舉成員。Converts the specified 16-bit signed integer to an enumeration member.

ToObject(Type, UInt64)

將指定的 64 位元不帶正負號的整數值轉換為列舉成員。Converts the specified 64-bit unsigned integer value to an enumeration member.

ToObject(Type, UInt32)

將指定的 32 位元不帶正負號的整數值轉換為列舉成員。Converts the specified 32-bit unsigned integer value to an enumeration member.

ToObject(Type, UInt16)

將指定的 16 位元不帶正負號的整數值轉換為列舉成員。Converts the specified 16-bit unsigned integer value to an enumeration member.

ToObject(Type, SByte)

將指定的 8 位元帶正負號的整數值轉換為列舉成員。Converts the specified 8-bit signed integer value to an enumeration member.

ToObject(Type, Object)

將具有整數值的指定物件轉換為列舉成員。Converts the specified object with an integer value to an enumeration member.

ToObject(Type, Int64)

將指定的 64 位元帶正負號的整數轉換為列舉成員。Converts the specified 64-bit signed integer to an enumeration member.

ToObject(Type, Int32)

將指定的 32 位元帶正負號的整數轉換為列舉成員。Converts the specified 32-bit signed integer to an enumeration member.

ToObject(Type, Byte)

將指定的 8 位元不帶正負號的整數轉換為列舉成員。Converts the specified 8-bit unsigned integer to an enumeration member.

ToObject(Type, Int16)

將指定的 16 位元帶正負號的整數轉換為列舉成員。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
Public Shared Function ToObject (enumType As Type, value As Short) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
Int16

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, Int16) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, Int16) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, UInt64)

重要

此 API 不符合 CLS 規範。

將指定的 64 位元不帶正負號的整數值轉換為列舉成員。Converts the specified 64-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt64 value);
public static object ToObject (Type enumType, ulong 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);
static member ToObject : Type * uint64 -> obj
Public Shared Function ToObject (enumType As Type, value As ULong) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
UInt64

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, UInt64) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, UInt64) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, UInt32)

重要

此 API 不符合 CLS 規範。

將指定的 32 位元不帶正負號的整數值轉換為列舉成員。Converts the specified 32-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt32 value);
public static object ToObject (Type enumType, uint 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);
static member ToObject : Type * uint32 -> obj
Public Shared Function ToObject (enumType As Type, value As UInteger) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
UInt32

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, UInt32) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, UInt32) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, UInt16)

重要

此 API 不符合 CLS 規範。

將指定的 16 位元不帶正負號的整數值轉換為列舉成員。Converts the specified 16-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt16 value);
public static object ToObject (Type enumType, ushort 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);
static member ToObject : Type * uint16 -> obj
Public Shared Function ToObject (enumType As Type, value As UShort) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
UInt16

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, UInt16) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, UInt16) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, SByte)

重要

此 API 不符合 CLS 規範。

將指定的 8 位元帶正負號的整數值轉換為列舉成員。Converts the specified 8-bit signed integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::SByte value);
public static object ToObject (Type enumType, 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);
static member ToObject : Type * sbyte -> obj
Public Shared Function ToObject (enumType As Type, value As SByte) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
SByte

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, SByte) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, SByte) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

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
Public Shared Function ToObject (enumType As Type, value As Object) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
Object

要轉換為列舉成員的值。The value convert to an enumeration member.

傳回

值為 value 的列舉物件。An enumeration object whose value is value.

屬性

例外狀況

enumTypevaluenullenumType or value is null.

enumType 不是 EnumenumType is not an Enum.

-或--or- value 不是類型 SByteInt16Int32Int64ByteUInt16UInt32UInt64value is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64.

備註

ToObject(Type, Object) 方法會將整數值 value 轉換為 value其基礎值的列舉成員。The ToObject(Type, Object) method converts the integral value value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, Int64)

將指定的 64 位元帶正負號的整數轉換為列舉成員。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
Public Shared Function ToObject (enumType As Type, value As Long) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
Int64

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, Int64) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, Int64) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, Int32)

將指定的 32 位元帶正負號的整數轉換為列舉成員。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
Public Shared Function ToObject (enumType As Type, value As Integer) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
Int32

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, Int32) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, Int32) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

ToObject(Type, Byte)

將指定的 8 位元不帶正負號的整數轉換為列舉成員。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
Public Shared Function ToObject (enumType As Type, value As Byte) As Object

參數

enumType
Type

要傳回的列舉類型。The enumeration type to return.

value
Byte

要轉換為列舉成員的值。The value to convert to an enumeration member.

傳回

設定為 value 的列舉執行個體。An instance of the enumeration set to value.

屬性

例外狀況

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

備註

ToObject(Type, Byte) 方法會將 value 轉換為其基礎值為 value的列舉成員。The ToObject(Type, Byte) method converts value to an enumeration member whose underlying value is value. 請注意,即使值超出 enumType 成員的範圍,轉換還是會成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要確保 valueenumType 列舉的有效基礎值,請將它傳遞給 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此轉換方法會傳回 Object類型的值。This conversion method returns a value of type Object. 然後,您可以將它轉換或轉換成 enumType類型的物件。You can then cast it or convert it to an object of type enumType.

另請參閱

適用於