ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>.IStructuralComparable.CompareTo(Object, IComparer) ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>.IStructuralComparable.CompareTo(Object, IComparer) ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>.IStructuralComparable.CompareTo(Object, IComparer) Method

定义

使用指定的比较器比较当前 ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> 实例与指定对象,并返回一个整数,该整数指示当前对象在排序顺序中的位置:是在指定对象之前、之后还是在与指定对象相同的位置。Compares the current ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order.

 virtual int System.Collections.IStructuralComparable.CompareTo(System::Object ^ other, System::Collections::IComparer ^ comparer) = System::Collections::IStructuralComparable::CompareTo;
int IStructuralComparable.CompareTo (object other, System.Collections.IComparer comparer);
Function CompareTo (other As Object, comparer As IComparer) As Integer Implements IStructuralComparable.CompareTo

参数

other
Object Object Object

要与当前实例进行比较的对象。The object to compare with the current instance.

comparer
IComparer IComparer IComparer

提供用于比较的自定义规则的对象。An object that provides custom rules for comparison.

返回

一个带符号整数,指示此实例和 other 在排序顺序中的相对位置,如下表所示。A signed integer that indicates the relative position of this instance and other in the sort order, as shown in the following table.

Value 描述Description
负整数A negative integer 此实例位于 other 之前。This instance precedes other.
Zero 此实例在排序顺序中的位置与 other 相同。This instance and other have the same position in the sort order.
正整数A positive integer 此实例位于 other 之后。This instance follows other.

实现

异常

注解

此成员是显式接口应用。This member is an explicit interface implementation. 仅可使用何时ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>实例转换为IStructuralComparable接口。It can only be used when the ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> instance is cast to an IStructuralComparable interface.

此方法允许您定义的自定义的比较ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象。This method lets you define customized comparisons of ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> objects. 例如,可以使用此方法为顺序ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象基于的特定组件的值。For example, you can use this method to order ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> objects based on the value of a specific component.

虽然可以直接调用此方法,通常称为通过对集合进行排序方法,包括IComparer参数集合的成员进行排序。Although this method can be called directly, it is most commonly called by collection-sorting methods that include IComparer parameters to order the members of a collection. 例如,调用Array.Sort(Array, IComparer)方法和Add方法SortedList对象,它通过使用实例化SortedList.SortedList(IComparer)构造函数。For example, it is called by the Array.Sort(Array, IComparer) method and the Add method of a SortedList object that is instantiated by using the SortedList.SortedList(IComparer) constructor.

注意

IStructuralComparable.CompareTo方法应在排序操作中使用。The IStructuralComparable.CompareTo method is intended for use in sorting operations. 它不应比较的主要目的在于确定两个对象是否相等。It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. 若要确定两个对象,调用IStructuralEquatable.Equals方法。To determine whether two objects are equal, call the IStructuralEquatable.Equals method.

适用于