共用方式為


LanguagePrimitives.TryConvertTo Method

Definition

Overloads

TryConvertTo(Object, Type, Object)

Sets result to valueToConvert converted to resultType.

TryConvertTo(Object, Type, IFormatProvider, Object)

Sets result to valueToConvert converted to resultType considering formatProvider for custom conversions, calling the Parse method and calling Convert.ChangeType.

TryConvertTo<T>(Object, T)

Sets result to valueToConvert converted to resultType.

TryConvertTo<T>(Object, IFormatProvider, T)

Sets result to valueToConvert converted to resultType considering formatProvider for custom conversions, calling the Parse method and calling Convert.ChangeType.

TryConvertTo(Object, Type, Object)

Sets result to valueToConvert converted to resultType.

public:
 static bool TryConvertTo(System::Object ^ valueToConvert, Type ^ resultType, [Runtime::InteropServices::Out] System::Object ^ % result);
public static bool TryConvertTo (object valueToConvert, Type resultType, out object result);
static member TryConvertTo : obj * Type * obj -> bool
Public Shared Function TryConvertTo (valueToConvert As Object, resultType As Type, ByRef result As Object) As Boolean

Parameters

valueToConvert
Object

Value to be converted and returned.

resultType
Type

Type to convert valueToConvert.

result
Object

Result of the conversion. This is valid only if the return is true.

Returns

False for conversion failure, true for success.

Remarks

This method is a variant of ConvertTo that does not throw exceptions if the conversion fails.

Applies to

TryConvertTo(Object, Type, IFormatProvider, Object)

Sets result to valueToConvert converted to resultType considering formatProvider for custom conversions, calling the Parse method and calling Convert.ChangeType.

public:
 static bool TryConvertTo(System::Object ^ valueToConvert, Type ^ resultType, IFormatProvider ^ formatProvider, [Runtime::InteropServices::Out] System::Object ^ % result);
public static bool TryConvertTo (object valueToConvert, Type resultType, IFormatProvider formatProvider, out object result);
static member TryConvertTo : obj * Type * IFormatProvider * obj -> bool
Public Shared Function TryConvertTo (valueToConvert As Object, resultType As Type, formatProvider As IFormatProvider, ByRef result As Object) As Boolean

Parameters

valueToConvert
Object

Value to be converted and returned.

resultType
Type

Type to convert valueToConvert.

formatProvider
IFormatProvider

Governing conversion of types.

result
Object

Result of the conversion. This is valid only if the return is true.

Returns

False for conversion failure, true for success.

Remarks

This method is a variant of ConvertTo that does not throw exceptions if the conversion fails.

Applies to

TryConvertTo<T>(Object, T)

Sets result to valueToConvert converted to resultType.

public:
generic <typename T>
 static bool TryConvertTo(System::Object ^ valueToConvert, [Runtime::InteropServices::Out] T % result);
public:
generic <typename T>
 static bool TryConvertTo(Platform::Object ^ valueToConvert, [Runtime::InteropServices::Out] T &  result);
template <typename T>
 static bool TryConvertTo(winrt::Windows::Foundation::IInspectable const & valueToConvert, [Runtime::InteropServices::Out] T & result);
public static bool TryConvertTo<T> (object valueToConvert, out T result);
static member TryConvertTo : obj * 'T -> bool
Public Shared Function TryConvertTo(Of T) (valueToConvert As Object, ByRef result As T) As Boolean

Type Parameters

T

Parameters

valueToConvert
Object

Value to be converted and returned.

result
T

Result of the conversion. This is valid only if the return is true.

Returns

False for conversion failure, true for success.

Remarks

This method is a variant of ConvertTo that does not throw exceptions if the conversion fails.

Applies to

TryConvertTo<T>(Object, IFormatProvider, T)

Sets result to valueToConvert converted to resultType considering formatProvider for custom conversions, calling the Parse method and calling Convert.ChangeType.

public:
generic <typename T>
 static bool TryConvertTo(System::Object ^ valueToConvert, IFormatProvider ^ formatProvider, [Runtime::InteropServices::Out] T % result);
public static bool TryConvertTo<T> (object valueToConvert, IFormatProvider formatProvider, out T result);
static member TryConvertTo : obj * IFormatProvider * 'T -> bool
Public Shared Function TryConvertTo(Of T) (valueToConvert As Object, formatProvider As IFormatProvider, ByRef result As T) As Boolean

Type Parameters

T

Parameters

valueToConvert
Object

Value to be converted and returned.

formatProvider
IFormatProvider

Governing conversion of types.

result
T

Result of the conversion. This is valid only if the return is true.

Returns

False for conversion failure, true for success.

Remarks

This method is a variant of ConvertTo that does not throw exceptions if the conversion fails.

Applies to