Tuple<T1>.IComparable.CompareTo(Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 Tuple<T1> 개체를 지정된 개체와 비교하고 현재 개체가 정렬 순서에서 지정된 개체와 이전, 이후 또는 같은 위치에 있는지 여부를 나타내는 정수를 반환합니다.
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
매개 변수
- obj
- Object
현재 인스턴스와 비교할 개체입니다.
반품
다음 표와 같이 이 인스턴스의 상대 위치와 obj 정렬 순서를 나타내는 부인 정수입니다.
| 값 | 설명 |
|---|---|
| 음수 정수 | 이 인스턴스는 앞에 섰습니다 obj.
|
| 0 | 이 인스턴스는 obj 정렬 순서에서 동일한 위치를 갖습니다.
|
| 양의 정수 | 이 인스턴스는 다음과 같습니다.obj
|
구현
예외
obj가 개체가 아닌 경우 Tuple<T1>
예제
다음 예제에서는 구성 요소가 값인 싱글톤 배열을 Double 만듭니다. 각 튜플 구성 요소의 값을 정렬되지 않은 순서로 표시하고 배열을 정렬한 다음 정렬된 순서로 값을 표시합니다. 이 예제에서는 메서드를 Tuple<T1>.IComparable.CompareTo 직접 호출하지 않습니다. 이 메서드는 배열의 각 요소에 Sort(Array) 대한 메서드에 의해 암시적으로 호출됩니다.
using System;
class Example
{
static void Main()
{
Tuple<Double>[] values = { Tuple.Create(13.54),
Tuple.Create(Double.NaN),
Tuple.Create(-189.42993),
Tuple.Create(Double.PositiveInfinity),
Tuple.Create(Double.Epsilon),
Tuple.Create(1.934E-17),
Tuple.Create(Double.NegativeInfinity),
Tuple.Create(-0.000000000003588),
null };
Console.WriteLine("The values in unsorted order:");
foreach (var value in values)
if (value != null)
Console.WriteLine(" {0}", value.Item1);
else
Console.WriteLine(" <null>");
Console.WriteLine();
Array.Sort(values);
Console.WriteLine("The values in sorted order:");
foreach (var value in values)
if (value != null)
Console.WriteLine(" {0}", value.Item1);
else
Console.WriteLine(" <null>");
}
}
// The example displays the following output:
// The values in unsorted order:
// 13.54
// NaN
// -189.42993
// Infinity
// 4.94065645841247E-324
// 1.934E-17
// -Infinity
// -3.588E-12
//
// The values in sorted order:
// NaN
// -Infinity
// -189.42993
// -3.588E-12
// 4.94065645841247E-324
// 1.934E-17
// 13.54
// Infinity
open System
let values =
[| Tuple.Create 13.54
Tuple.Create Double.NaN
Tuple.Create -189.42993
Tuple.Create Double.PositiveInfinity
Tuple.Create Double.Epsilon
Tuple.Create 1.934E-17
Tuple.Create Double.NegativeInfinity
Tuple.Create -0.000000000003588
null |]
printfn "The values in unsorted order:"
for value in values do
printfn $" %A{value.Item1}"
printfn ""
Array.Sort values
printfn "The values sorted in descending order:"
for value in values do
printfn $" %A{value.Item1}"
// The example displays the following output:
// The values in unsorted order:
// 13.54
// NaN
// -189.42993
// Infinity
// 4.94065645841247E-324
// 1.934E-17
// -Infinity
// -3.588E-12
//
// The values in sorted order:
// NaN
// -Infinity
// -189.42993
// -3.588E-12
// 4.94065645841247E-324
// 1.934E-17
// 13.54
// Infinity
Module Example
Sub Main()
Dim values() = { Tuple.Create(13.54),
Tuple.Create(Double.NaN),
Tuple.Create(-189.42993),
Tuple.Create(Double.PositiveInfinity),
Tuple.Create(Double.Epsilon),
Tuple.Create(1.934E-17),
Tuple.Create(Double.NegativeInfinity),
Tuple.Create(-0.000000000003588),
Nothing}
Console.WriteLine("The values in unsorted order:")
For Each value In values
If value IsNot Nothing Then
Console.WriteLine(" {0}", value.Item1)
Else
Console.WriteLine(" <null>")
End If
Next
Console.WriteLine()
Array.Sort(values)
Console.WriteLine("The values in sorted order:")
For Each value In values
If value IsNot Nothing Then
Console.WriteLine(" {0}", value.Item1)
Else
Console.WriteLine(" <null>")
End If
Next
End Sub
End Module
' The example displays the following output:
' The values in unsorted order:
' 13.54
' NaN
' -189.42993
' Infinity
' 4.94065645841247E-324
' 1.934E-17
' -Infinity
' -3.588E-12
'
' The values in sorted order:
' NaN
' -Infinity
' -189.42993
' -3.588E-12
' 4.94065645841247E-324
' 1.934E-17
' 13.54
' Infinity
설명
이 멤버는 명시적 인터페이스 멤버 구현입니다. 인스턴스가 인터페이스로 Tuple<T1> 캐스팅 IComparable 되는 경우에만 사용할 수 있습니다.
이 메서드는 클래스에 IComparable.CompareTo 대한 구현을 Tuple<T1> 제공합니다. 메서드를 직접 호출할 수 있지만 가장 일반적으로 컬렉션의 멤버를 정렬 하는 등의 컬렉션 정렬 메서드 Array.Sort(Array)SortedList.Add의 기본 오버 로드에 의해 호출 됩니다.
Caution
이 Tuple<T1>.IComparable.CompareTo 메서드는 정렬 작업에 사용하기 위한 것입니다. 비교의 주요 목적이 두 개체가 같은지 여부를 확인하는 경우에는 사용하지 않아야 합니다. 두 개체가 같은지 여부를 확인하려면 메서드를 호출합니다 Equals .
이 메서드는 Tuple<T1>.IComparable.CompareTo 기본 개체 비교자를 사용합니다.