Compartilhar via


LanguagePrimitives.TryCompare Method

Definition

Overloads

TryCompare(Object, Object, Int32)

Tries to compare first and second, converting second to the type of the first, if necessary. If a conversion is needed but fails, false is return.

TryCompare(Object, Object, Boolean, Int32)

Tries to compare first and second, converting second to the type of the first, if necessary. If a conversion is needed but fails, false is return.

TryCompare(Object, Object, Boolean, IFormatProvider, Int32)

Tries to compare first and second, converting second to the type of the first, if necessary. If a conversion is needed but fails, false is return.

TryCompare(Object, Object, Int32)

Tries to compare first and second, converting second to the type of the first, if necessary. If a conversion is needed but fails, false is return.

public static bool TryCompare (object first, object second, out int result);
static member TryCompare : obj * obj * int -> bool
Public Shared Function TryCompare (first As Object, second As Object, ByRef result As Integer) As Boolean

Parameters

first
Object

First comparison value.

second
Object

Second comparison value.

result
Int32

Less than zero if first is smaller than second, more than zero if it is greater or zero if they are the same.

Returns

True if the comparison was successful, false otherwise.

Applies to

TryCompare(Object, Object, Boolean, Int32)

Tries to compare first and second, converting second to the type of the first, if necessary. If a conversion is needed but fails, false is return.

public static bool TryCompare (object first, object second, bool ignoreCase, out int result);
static member TryCompare : obj * obj * bool * int -> bool
Public Shared Function TryCompare (first As Object, second As Object, ignoreCase As Boolean, ByRef result As Integer) As Boolean

Parameters

first
Object

First comparison value.

second
Object

Second comparison value.

ignoreCase
Boolean

Used if both values are strings.

result
Int32

Less than zero if first is smaller than second, more than zero if it is greater or zero if they are the same.

Returns

True if the comparison was successful, false otherwise.

Applies to

TryCompare(Object, Object, Boolean, IFormatProvider, Int32)

Tries to compare first and second, converting second to the type of the first, if necessary. If a conversion is needed but fails, false is return.

public static bool TryCompare (object first, object second, bool ignoreCase, IFormatProvider formatProvider, out int result);
static member TryCompare : obj * obj * bool * IFormatProvider * int -> bool
Public Shared Function TryCompare (first As Object, second As Object, ignoreCase As Boolean, formatProvider As IFormatProvider, ByRef result As Integer) As Boolean

Parameters

first
Object

First comparison value.

second
Object

Second comparison value.

ignoreCase
Boolean

Used if both values are strings.

formatProvider
IFormatProvider

Used in type conversions and if both values are strings.

result
Int32

Less than zero if first is smaller than second, more than zero if it is greater or zero if they are the same.

Returns

True if the comparison was successful, false otherwise.

Exceptions

The parameter formatProvider is not a CultureInfo.

Applies to