SortKey.Compare メソッド
2 つの並べ替えキーを比較します。
Public Shared Function Compare( _
ByVal sortkey1 As SortKey, _ ByVal sortkey2 As SortKey _) As Integer
[C#]
public static int Compare(SortKeysortkey1,SortKeysortkey2);
[C++]
public: static int Compare(SortKey* sortkey1,SortKey* sortkey2);
[JScript]
public static function Compare(
sortkey1 : SortKey,sortkey2 : SortKey) : int;
パラメータ
- sortkey1
比較対象の第 1 並べ替えキー。 - sortkey2
比較対象の第 2 並べ替えキー。
戻り値
値 | 説明 |
---|---|
0 | 2 つの並べ替えキーは同じです。 |
0 より小さい値 | sortkey1 が sortkey2 より小さい。 |
0 より大きい値 | sortkey1 が sortkey2 より大きい。 |
解説
Compare の動作は CompareInfo.Compare と同じです。 Equals とは異なり、 Compare は CompareInfo.GetSortKey の CompareOptions の設定による影響を受けません。また、 Equals とは異なり、 Compare の場合は、各 SortKey パラメータが等しいと見なされる条件として、それらが同じ System.Globalization.CompareInfo インスタンスから生成されたものである必要はありません。 Compare は、両方の SortKey インスタンスが同じ OriginalString を持ち、かつ OriginalString が両方の SortKey インスタンスのカルチャで同じ並び替え順序になっていれば、0 を返します。
使用例
[Visual Basic, C#, C++] 異なる並べ替え順序を持つ CultureInfo インスタンスを使用して作成した SortKey オブジェクトを比較するコードを次の例に示します。
Imports System
Imports System.Globalization
Public Class SamplesSortKey
Public Shared Sub Main()
' Creates a SortKey using the en-US culture.
Dim myComp_enUS As CompareInfo = New CultureInfo("en-US", False).CompareInfo
Dim mySK1 As SortKey = myComp_enUS.GetSortKey("llama")
' Creates a SortKey using the es-ES culture with international sort.
Dim myComp_esES As CompareInfo = New CultureInfo("es-ES", False).CompareInfo
Dim mySK2 As SortKey = myComp_esES.GetSortKey("llama")
' Creates a SortKey using the es-ES culture with traditional sort.
Dim myComp_es As CompareInfo = New CultureInfo(&H40A, False).CompareInfo
Dim mySK3 As SortKey = myComp_es.GetSortKey("llama")
' Compares the en-US SortKey with each of the es-ES SortKey objects.
Console.WriteLine("Comparing ""llama"" in en-US and in es-ES with international sort : {0}", SortKey.Compare(mySK1, mySK2))
Console.WriteLine("Comparing ""llama"" in en-US and in es-ES with traditional sort : {0}", SortKey.Compare(mySK1, mySK3))
End Sub 'Main
End Class 'SamplesSortKey
'This code produces the following output.
'
'Comparing "llama" in en-US and in es-ES with international sort : 0
'Comparing "llama" in en-US and in es-ES with traditional sort : -1
[C#]
using System;
using System.Globalization;
public class SamplesSortKey {
public static void Main() {
// Creates a SortKey using the en-US culture.
CompareInfo myComp_enUS = new CultureInfo("en-US",false).CompareInfo;
SortKey mySK1 = myComp_enUS.GetSortKey( "llama" );
// Creates a SortKey using the es-ES culture with international sort.
CompareInfo myComp_esES = new CultureInfo("es-ES",false).CompareInfo;
SortKey mySK2 = myComp_esES.GetSortKey( "llama" );
// Creates a SortKey using the es-ES culture with traditional sort.
CompareInfo myComp_es = new CultureInfo(0x040A,false).CompareInfo;
SortKey mySK3 = myComp_es.GetSortKey( "llama" );
// Compares the en-US SortKey with each of the es-ES SortKey objects.
Console.WriteLine( "Comparing \"llama\" in en-US and in es-ES with international sort : {0}", SortKey.Compare( mySK1, mySK2 ) );
Console.WriteLine( "Comparing \"llama\" in en-US and in es-ES with traditional sort : {0}", SortKey.Compare( mySK1, mySK3 ) );
}
}
/*
This code produces the following output.
Comparing "llama" in en-US and in es-ES with international sort : 0
Comparing "llama" in en-US and in es-ES with traditional sort : -1
*/
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
int main()
{
// Creates a SortKey using the en-US culture.
CultureInfo * MyCI = new CultureInfo(S"en-US", false);
CompareInfo* myComp_enUS = MyCI -> CompareInfo;
SortKey * mySK1 = myComp_enUS -> GetSortKey(S"llama");
// Creates a SortKey using the es-ES culture with international sort.
MyCI = new CultureInfo(S"es-ES", false);
CompareInfo* myComp_esES = MyCI -> CompareInfo;
SortKey * mySK2 = myComp_esES -> GetSortKey(S"llama");
// Creates a SortKey using the es-ES culture with traditional sort.
MyCI = new CultureInfo(0x040A, false);
CompareInfo* myComp_es = MyCI -> CompareInfo;
SortKey * mySK3 = myComp_es -> GetSortKey(S"llama");
// Compares the en-US SortKey with each of the es-ES SortKey objects.
Console::WriteLine(S"Comparing \"llama\" in en-US and in es-ES with international sort : {0}",
__box(SortKey::Compare(mySK1, mySK2)));
Console::WriteLine(S"Comparing \"llama\" in en-US and in es-ES with traditional sort : {0}",
__box(SortKey::Compare(mySK1, mySK3)));
}
/*
This code produces the following output.
Comparing S"llama" in en-US and in es-ES with international sort : 0
Comparing S"llama" in en-US and in es-ES with traditional sort : -1
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ