Freigeben über


CompareInfo.GetCompareInfo-Methode (Int32)

Initialisiert eine neue Instanz der CompareInfo-Klasse, die der Kultur mit dem angegebenen Bezeichner zugeordnet ist.

Overloads Public Shared Function GetCompareInfo( _
   ByVal culture As Integer _) As CompareInfo
[C#]
public static CompareInfo GetCompareInfo(intculture);
[C++]
public: static CompareInfo* GetCompareInfo(intculture);
[JScript]
public static function GetCompareInfo(
   culture : int) : CompareInfo;

Parameter

  • culture
    Eine ganze Zahl, die den Kulturbezeichner darstellt.

Rückgabewert

Eine neue Instanz der CompareInfo-Klasse, die der Kultur mit dem angegebenen Bezeichner zugeordnet ist und in der aktuellen Assembly Methoden zum Zeichenfolgenvergleich verwendet.

Hinweise

Wenn eine Sicherheitsentscheidung von einem Zeichenfolgenvergleich oder einer Änderung der Groß-/Kleinschreibung abhängt, stellen Sie mit Hilfe der InvariantCulture sicher, dass das Verhalten ungeachtet der Kultureinstellungen des Systems konsistent ist.

Beispiel

[Visual Basic, C#, C++] Im folgenden Codebeispiel werden zwei Zeichenfolgen mit Hilfe der verschiedenen CompareInfo-Instanzen verglichen: einer CompareInfo-Instanz für die Kultur "Spanisch - Spanien" mit internationaler Sortierung, einer CompareInfo-Instanz für die Kultur "Spanisch - Spanien" mit traditioneller Sortierung und einer CompareInfo-Instanz, der InvariantCulture zugeordnet ist.

 
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] Für JScript ist kein Beispiel verfügbar. Klicken Sie zum Anzeigen eines Beispiels für Visual Basic, C# oder C++ in der linken oberen Ecke der Seite auf die Schaltfläche "Sprachfilter" Sprachfilter.

Anforderungen

Plattformen: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003-Familie, .NET Compact Framework - Windows CE .NET

Siehe auch

CompareInfo-Klasse | CompareInfo-Member | System.Globalization-Namespace | CompareInfo.GetCompareInfo-Überladungsliste