SortKey.Compare(SortKey, SortKey) 메서드
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
두 정렬 키를 비교합니다.
public:
static int Compare(System::Globalization::SortKey ^ sortkey1, System::Globalization::SortKey ^ sortkey2);
public static int Compare (System.Globalization.SortKey sortkey1, System.Globalization.SortKey sortkey2);
static member Compare : System.Globalization.SortKey * System.Globalization.SortKey -> int
Public Shared Function Compare (sortkey1 As SortKey, sortkey2 As SortKey) As Integer
- sortkey1
- SortKey
비교할 첫째 정렬 키입니다.
- sortkey2
- SortKey
비교할 둘째 정렬 키입니다.
sortkey1
과(와) sortkey2
간의 관계를 나타내는 부호 있는 정수입니다.
값 | 조건 |
---|---|
0보다 작음 | sortkey1 가 sortkey2 보다 작은 경우
|
0 | sortkey1 이(가) sortkey2 와 같은 경우.
|
0보다 큼 | sortkey1 가 sortkey2 보다 큰 경우
|
sortkey1
또는 sortkey2
가 null
인 경우
다음 코드 예제에서는 메서드와 동등한 CompareInfo.Compare(String, String, CompareOptions) 메서드를 Compare 사용하는 두 문자열을 비교합니다.
// This code example demonstrates the CompareInfo.Compare() and
// SortKey.Compare() methods.
using System;
using System.Globalization;
class Sample
{
public static void Main()
{
string lowerABC = "abc";
string upperABC = "ABC";
int result = 0;
// Create a CompareInfo object for the en-US culture.
Console.WriteLine("\nCreate a CompareInfo object for the en-US culture...\n");
CompareInfo cmpi = CompareInfo.GetCompareInfo("en-US");
// Alternatively:
// CompareInfo cmpi = new CultureInfo("en-US").CompareInfo;
// Create sort keys for lowercase and uppercase "abc", the en-US culture, and
// ignore case.
SortKey sk1LowerIgnCase = cmpi.GetSortKey(lowerABC, CompareOptions.IgnoreCase);
SortKey sk2UpperIgnCase = cmpi.GetSortKey(upperABC, CompareOptions.IgnoreCase);
// Create sort keys for lowercase and uppercase "abc", the en-US culture, and
// use case.
SortKey sk1LowerUseCase = cmpi.GetSortKey(lowerABC, CompareOptions.None);
SortKey sk2UpperUseCase = cmpi.GetSortKey(upperABC, CompareOptions.None);
// Compare lowercase and uppercase "abc", ignoring case and using CompareInfo.
result = cmpi.Compare(lowerABC, upperABC, CompareOptions.IgnoreCase);
Display(result, "CompareInfo, Ignore case", lowerABC, upperABC);
// Compare lowercase and uppercase "abc", ignoring case and using SortKey.
result = SortKey.Compare(sk1LowerIgnCase, sk2UpperIgnCase);
Display(result, "SortKey, Ignore case", lowerABC, upperABC);
Console.WriteLine();
// Compare lowercase and uppercase "abc", using case and using CompareInfo.
result = cmpi.Compare(lowerABC, upperABC, CompareOptions.None);
Display(result, "CompareInfo, Use case", lowerABC, upperABC);
// Compare lowercase and uppercase "abc", using case and using SortKey.
result = SortKey.Compare(sk1LowerUseCase, sk2UpperUseCase);
Display(result, "SortKey, Use case", lowerABC, upperABC);
}
// Display the results of a comparison.
private static void Display(int compareResult, string title,
string lower, string upper)
{
string lessThan = "less than ";
string equalTo = "equal to ";
string greaterThan = "greater than ";
string resultPhrase = null;
string format = "{0}:\n \"{1}\" is {2}\"{3}\".";
if (compareResult < 0) resultPhrase = lessThan;
else if (compareResult > 0) resultPhrase = greaterThan;
else resultPhrase = equalTo;
Console.WriteLine(format, title, lower, resultPhrase, upper);
}
}
/*
This code example produces the following results:
Create a CompareInfo object for the en-US culture...
CompareInfo, Ignore case:
"abc" is equal to "ABC".
SortKey, Ignore case:
"abc" is equal to "ABC".
CompareInfo, Use case:
"abc" is less than "ABC".
SortKey, Use case:
"abc" is less than "ABC".
*/
' This code example demonstrates the CompareInfo.Compare() and
' SortKey.Compare() methods.
Imports System.Globalization
Class Sample
Public Shared Sub Main()
Dim lowerABC As String = "abc"
Dim upperABC As String = "ABC"
Dim result As Integer = 0
' Create a CompareInfo object for the en-US culture.
Console.WriteLine(vbCrLf & _
"Create a CompareInfo object for the en-US culture..." & _
vbCrLf)
Dim cmpi As CompareInfo = CompareInfo.GetCompareInfo("en-US")
' Alternatively:
' Dim cmpi As CompareInfo = New CultureInfo("en-US").CompareInfo
' Create sort keys for lowercase and uppercase "abc", the en-US culture, and
' ignore case.
Dim sk1LowerIgnCase As SortKey = cmpi.GetSortKey(lowerABC, CompareOptions.IgnoreCase)
Dim sk2UpperIgnCase As SortKey = cmpi.GetSortKey(upperABC, CompareOptions.IgnoreCase)
' Create sort keys for lowercase and uppercase "abc", the en-US culture, and
' use case.
Dim sk1LowerUseCase As SortKey = cmpi.GetSortKey(lowerABC, CompareOptions.None)
Dim sk2UpperUseCase As SortKey = cmpi.GetSortKey(upperABC, CompareOptions.None)
' Compare lowercase and uppercase "abc", ignoring case and using CompareInfo.
result = cmpi.Compare(lowerABC, upperABC, CompareOptions.IgnoreCase)
Display(result, "CompareInfo, Ignore case", lowerABC, upperABC)
' Compare lowercase and uppercase "abc", ignoring case and using SortKey.
result = SortKey.Compare(sk1LowerIgnCase, sk2UpperIgnCase)
Display(result, "SortKey, Ignore case", lowerABC, upperABC)
Console.WriteLine()
' Compare lowercase and uppercase "abc", using case and using CompareInfo.
result = cmpi.Compare(lowerABC, upperABC, CompareOptions.None)
Display(result, "CompareInfo, Use case", lowerABC, upperABC)
' Compare lowercase and uppercase "abc", using case and using SortKey.
result = SortKey.Compare(sk1LowerUseCase, sk2UpperUseCase)
Display(result, "SortKey, Use case", lowerABC, upperABC)
End Sub
' Display the results of a comparison.
Private Shared Sub Display(ByVal compareResult As Integer, _
ByVal title As String, _
ByVal lower As String, _
ByVal upper As String)
Dim lessThan As String = "less than "
Dim equalTo As String = "equal to "
Dim greaterThan As String = "greater than "
Dim resultPhrase As String = Nothing
Dim format As String = "{0}:" & vbCrLf & " ""{1}"" is {2}""{3}""."
If compareResult < 0 Then
resultPhrase = lessThan
ElseIf compareResult > 0 Then
resultPhrase = greaterThan
Else
resultPhrase = equalTo
End If
Console.WriteLine(format, title, lower, resultPhrase, upper)
End Sub
End Class
'
'This code example produces the following results:
'
'Create a CompareInfo object for the en-US culture...
'
'CompareInfo, Ignore case:
' "abc" is equal to "ABC".
'SortKey, Ignore case:
' "abc" is equal to "ABC".
'
'CompareInfo, Use case:
' "abc" is less than "ABC".
'SortKey, Use case:
' "abc" is less than "ABC".
'
메서드는 CompareKeyData 및 sortkey2
매개 변수의 sortkey1
속성을 비교합니다. 메서드는 메서드와 동일한 결과를 생성합니다 CompareInfo.Compare .
메서드 및 정렬 키 비교에 대한 Compare 자세한 내용은 클래스 항목을 참조 SortKey 하세요.
.NET 피드백
.NET은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.