Share via


CompareInfo.GetCompareInfo メソッド

CompareInfo クラスの新しいインスタンスを初期化します。

オーバーロードの一覧

指定した識別子を持つカルチャに関連付けられている CompareInfo クラスの新しいインスタンスを初期化します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function GetCompareInfo(Integer) As CompareInfo

[C#] public static CompareInfo GetCompareInfo(int);

[C++] public: static CompareInfo* GetCompareInfo(int);

[JScript] public static function GetCompareInfo(int) : CompareInfo;

指定した名前を持つカルチャに関連付けられている CompareInfo クラスの新しいインスタンスを初期化します。

[Visual Basic] Overloads Public Shared Function GetCompareInfo(String) As CompareInfo

[C#] public static CompareInfo GetCompareInfo(string);

[C++] public: static CompareInfo* GetCompareInfo(String*);

[JScript] public static function GetCompareInfo(String) : CompareInfo;

指定した識別子を持つカルチャに関連付けられており、指定した Assembly 内の文字列比較メソッドを使用する、 CompareInfo クラスの新しいインスタンスを初期化します。

[Visual Basic] Overloads Public Shared Function GetCompareInfo(Integer, Assembly) As CompareInfo

[C#] public static CompareInfo GetCompareInfo(int, Assembly);

[C++] public: static CompareInfo* GetCompareInfo(int, Assembly*);

[JScript] public static function GetCompareInfo(int, Assembly) : CompareInfo;

指定した名前を持つカルチャに関連付けられており、指定した Assembly 内の文字列比較メソッドを使用する、 CompareInfo クラスの新しいインスタンスを初期化します。

[Visual Basic] Overloads Public Shared Function GetCompareInfo(String, Assembly) As CompareInfo

[C#] public static CompareInfo GetCompareInfo(string, Assembly);

[C++] public: static CompareInfo* GetCompareInfo(String*, Assembly*);

[JScript] public static function GetCompareInfo(String, Assembly) : CompareInfo;

使用例

[Visual Basic, C#, C++] 次に示すのは、複数の異なる CompareInfo インスタンスを使用して、2 つの文字列を比較するコード例です。使用するインスタンスは、"スペイン語 - スペイン" カルチャの国際対応並べ替え順序を使用した CompareInfo インスタンス、"スペイン語 - スペイン" カルチャの従来の並べ替え順序を使用した CompareInfo インスタンス、および InvariantCulture を使用した CompareInfo インスタンスです。

[Visual Basic, C#, C++] メモ   ここでは、GetCompareInfo のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Defines the strings to compare.
      Dim myStr1 As [String] = "calle"
      Dim myStr2 As [String] = "calor"

      ' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
      Dim myCompIntl As CompareInfo = CompareInfo.GetCompareInfo("es-ES")

      ' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
      Dim myCompTrad As CompareInfo = CompareInfo.GetCompareInfo(&H40A)

      ' Uses the CompareInfo property of the InvariantCulture.
      Dim myCompInva As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' Compares two strings using myCompIntl.
      Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1, myStr2)
      Console.WriteLine("   With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, myStr2))
      Console.WriteLine("   With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, myStr2))
      Console.WriteLine("   With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, myStr2))

   End Sub 'Main 

End Class 'SamplesCompareInfo


'This code produces the following output.
'
'Comparing "calle" and "calor"
'   With myCompIntl.Compare: -1
'   With myCompTrad.Compare: 1
'   With myCompInva.Compare: -1


[C#] 
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Defines the strings to compare.
      String myStr1 = "calle";
      String myStr2 = "calor";

      // Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
      CompareInfo myCompIntl = CompareInfo.GetCompareInfo( "es-ES" );
      
      // Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
      CompareInfo myCompTrad = CompareInfo.GetCompareInfo( 0x040A );

      // Uses the CompareInfo property of the InvariantCulture.
      CompareInfo myCompInva = CultureInfo.InvariantCulture.CompareInfo;

      // Compares two strings using myCompIntl.
      Console.WriteLine( "Comparing \"{0}\" and \"{1}\"", myStr1, myStr2 );
      Console.WriteLine( "   With myCompIntl.Compare: {0}", myCompIntl.Compare( myStr1, myStr2 ) );
      Console.WriteLine( "   With myCompTrad.Compare: {0}", myCompTrad.Compare( myStr1, myStr2 ) );
      Console.WriteLine( "   With myCompInva.Compare: {0}", myCompInva.Compare( myStr1, myStr2 ) );

   }

}


/*
This code produces the following output.

Comparing "calle" and "calor"
   With myCompIntl.Compare: -1
   With myCompTrad.Compare: 1
   With myCompInva.Compare: -1

*/

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main() {
   // Defines the strings to compare.
   String*  myStr1 = S"calle";
   String*  myStr2 = S"calor";

   // Uses GetCompareInfo to create the CompareInfo that 
   // uses the S"es-ES" culture with international sort.
   CompareInfo*  myCompIntl = CompareInfo::GetCompareInfo(S"es-ES");

   // Uses GetCompareInfo to create the CompareInfo that 
   // uses the S"es-ES" culture with traditional sort.
   CompareInfo*  myCompTrad = CompareInfo::GetCompareInfo(0x040A);

   // Uses the CompareInfo property of the InvariantCulture.
   CompareInfo*  myCompInva = CultureInfo::InvariantCulture->CompareInfo;

   // Compares two strings using myCompIntl.
   Console::WriteLine(S"Comparing \"{0}\" and \"{1}\"", myStr1, myStr2);
      Console::WriteLine(S"   With myCompIntl::Compare: {0}", 
         __box(myCompIntl->Compare(myStr1, myStr2)));
   Console::WriteLine(S"   With myCompTrad::ompare: {0}", 
      __box(myCompTrad->Compare(myStr1, myStr2)));
   Console::WriteLine(S"   With myCompInva::Compare: {0}", 
      __box(myCompInva->Compare(myStr1, myStr2)));
}

/*
This code produces the following output.

Comparing "calle" and "calor"
   With myCompIntl::Compare: -1
   With myCompTrad::ompare: 1
   With myCompInva::Compare: -1
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

CompareInfo クラス | CompareInfo メンバ | System.Globalization 名前空間