Comparer<T>.Default 속성

정의

제네릭 인수에서 지정한 형식의 기본 정렬 순서 비교자를 반환합니다.

public:
 static property System::Collections::Generic::Comparer<T> ^ Default { System::Collections::Generic::Comparer<T> ^ get(); };
public static System.Collections.Generic.Comparer<T> Default { get; }
static member Default : System.Collections.Generic.Comparer<'T>
Public Shared ReadOnly Property Default As Comparer(Of T)

속성 값

Comparer<T>을 상속하고 T 형식에 대한 정렬 순서 비교자의 역할을 하는 개체입니다.

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다는 Default 기본 비교를 수행 하는 개체를 가져오는 속성입니다. 이 예제는에 대해 제공 된 큰 예제의 일부는 Comparer<T> 클래스입니다.

// Get the default comparer that
// sorts first by the height.
Comparer<Box> defComp = Comparer<Box>.Default;

// Calling Boxes.Sort() with no parameter
// is the same as calling Boxs.Sort(defComp)
// because they are both using the default comparer.
Boxes.Sort();

foreach (Box bx in Boxes)
{
    Console.WriteLine("{0}\t{1}\t{2}",
        bx.Height.ToString(), bx.Length.ToString(),
        bx.Width.ToString());
}
' Get the default comparer that 
' sorts first by the height.
Dim defComp As Comparer(Of Box) = Comparer(Of Box).Default

' Calling Boxes.Sort() with no parameter
' is the same as calling Boxs.Sort(defComp)
' because they are both using the default comparer.
Boxes.Sort()

For Each bx As Box In Boxes
    Console.WriteLine("{0}" & vbTab & "{1}" & vbTab & "{2}", _
                      bx.Height.ToString(), _
                      bx.Length.ToString(), _
                      bx.Width.ToString())
Next bx

설명

Comparer<T> 이 속성에서 반환 된 System.IComparable<T> 제네릭 인터페이스를 사용 하 여 (IComparable<T>C#에서, IComparable(Of T) Visual Basic에서) 두 개체를 비교 합니다. 형식 T 이 제네릭 인터페이스를 System.IComparable<T> 구현하지 않으면 이 속성은 인터페이스를 사용하는 System.IComparableComparer<T> 반환합니다.

호출자 참고

문자열 비교의 경우 클래스를 StringComparer 사용하는 Comparer<String> 것이 좋습니다(Comparer(Of String) Visual Basic의 경우). 클래스의 속성은 StringComparer 문화권 민감도 및 대/소문자 구분의 다양한 조합으로 문자열 비교를 수행하는 미리 정의된 인스턴스를 반환합니다. 대/소문자 구분 및 문화권 민감도는 동일한 StringComparer 인스턴스의 멤버 간에 일치합니다.

문화권별 비교에 대한 자세한 내용은 네임스페이 System.Globalization 스 및 세계화 및 지역화를 참조하세요.

적용 대상

추가 정보