StructuralComparisons.StructuralComparer StructuralComparisons.StructuralComparer StructuralComparisons.StructuralComparer StructuralComparisons.StructuralComparer Property

定義

取得預先定義的物件,這個物件會執行兩個物件的結構比較。Gets a predefined object that performs a structural comparison of two objects.

public:
 static property System::Collections::IComparer ^ StructuralComparer { System::Collections::IComparer ^ get(); };
public static System.Collections.IComparer StructuralComparer { get; }
member this.StructuralComparer : System.Collections.IComparer
Public Shared ReadOnly Property StructuralComparer As IComparer

屬性值

預先定義的物件,用來執行兩個集合物件的結構比較。A predefined object that is used to perform a structural comparison of two collection objects.

備註

IComparer這個屬性所傳回的物件傳遞給比較方法的集合物件,例如Array.IStructuralComparable.CompareTo(Object, IComparer)或是Tuple<T1,T2,T3>.IStructuralComparable.CompareTo(Object, IComparer)、 其Compare陣列的每個成員或 tuple 的每個元件,會呼叫方法。When the IComparer object returned by this property is passed to the comparison method of a collection object, such as Array.IStructuralComparable.CompareTo(Object, IComparer) or Tuple<T1,T2,T3>.IStructuralComparable.CompareTo(Object, IComparer), its Compare method is called for each member of an array or for each component of a tuple. 這個實作Compare方法,如下所示運作時,它會比較每個項目集合物件與另一個集合物件的對應項目:This implementation of the Compare method behaves as follows when it compares each item of a collection object with the corresponding item of another collection object:

  • 它會考慮兩個項目null視為相等,並考量會少於一個項目不是 null,null 項目。It considers two items that are null to be equal, and considers a null item to be less than an item that is not null.

  • 在比較中的第一個項目是否可以轉換成IStructuralComparable物件 (亦即,如果它是實作的集合物件時,才IStructuralComparable介面),它會呼叫CompareTo方法。If the first item in the comparison can be cast to an IStructuralComparable object (in other words, if it is a collection object that implements the IStructuralComparable interface), it calls the CompareTo method.

  • 如果在比較中的第一個項目無法轉換成IStructuralComparable物件 (亦即,如果它不是實作的集合物件時,才IStructuralComparable介面),它會呼叫Comparer.Default.Compare方法。If the first item in the comparison cannot be cast to an IStructuralComparable object (in other words, if it is not a collection object that implements the IStructuralComparable interface), it calls the Comparer.Default.Compare method.

適用於

另請參閱