Boolean.IComparable.CompareTo(Object) Method


将当前实例与同一类型的另一个对象进行比较,并返回一个整数,该整数指示当前实例在排序顺序中的位置是位于另一个对象之前、之后还是与其位置相同。Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

 virtual int System.IComparable.CompareTo(System::Object ^ obj) = IComparable::CompareTo;
int IComparable.CompareTo (object obj);
abstract member System.IComparable.CompareTo : obj -> int
override this.System.IComparable.CompareTo : obj -> int
Function CompareTo (obj As Object) As Integer Implements IComparable.CompareTo



要比较的对象。The object to compare.



一个值,指示要比较的对象的相对顺序。A value that indicates the relative order of the objects being compared.



此成员是显式接口成员实现。This member is an explicit interface member implementation. 它只能在 Boolean 实例被强制转换为 IComparable 接口时使用。It can be used only when the Boolean instance is cast to an IComparable interface.

返回值具有以下含义:The return value has these meanings:

Value 含义Meaning
小于零Less than zero 此实例在排序顺序中位于 obj 之前。This instance precedes obj in the sort order.
Zero 此实例在排序顺序中的位置与 obj 相同。This instance occurs in the same position in the sort order as obj.
大于零Greater than zero 此实例在排序顺序中位于 obj 之后。This instance follows obj in the sort order.

Applies to