CompareInfo.GetCompareInfo Metodo

Definizione

Inizializza un nuovo oggetto CompareInfo.

Overload

GetCompareInfo(Int32)

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura con l'identificatore specificato.

GetCompareInfo(String)

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura con il nome specificato.

GetCompareInfo(Int32, Assembly)

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura specificate e che usa i metodi di confronto tra stringhe nell'oggetto Assembly specificato.

GetCompareInfo(String, Assembly)

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura specificate e che usa i metodi di confronto tra stringhe nell'oggetto Assembly specificato.

GetCompareInfo(Int32)

Origine:
CompareInfo.cs
Origine:
CompareInfo.cs
Origine:
CompareInfo.cs

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura con l'identificatore specificato.

C#
public static System.Globalization.CompareInfo GetCompareInfo (int culture);

Parametri

culture
Int32

Intero che rappresenta l'identificatore di impostazioni cultura.

Restituisce

Nuovo oggetto CompareInfo associato alle impostazioni cultura con l'identificatore specificato che usa i metodi di confronto tra stringhe nell'oggetto Assembly corrente.

Esempio

Nell'esempio seguente vengono confrontate parti di due stringhe usando i diversi CompareInfo oggetti:

  • CompareInfo oggetto associato alla cultura spagnola (Spagna) con l'ordinamento internazionale

  • CompareInfo oggetto associato alla cultura spagnola (Spagna) con l'ordinamento tradizionale

  • CompareInfo oggetto associato all'oggetto InvariantCulture

C#
// The following code example compares two strings using the different CompareInfo instances:
//    a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
//    a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
//    a CompareInfo instance associated with the InvariantCulture.

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

*/

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetCompareInfo(String)

Origine:
CompareInfo.cs
Origine:
CompareInfo.cs
Origine:
CompareInfo.cs

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura con il nome specificato.

C#
public static System.Globalization.CompareInfo GetCompareInfo (string name);

Parametri

name
String

Stringa che rappresenta il nome delle impostazioni cultura.

Restituisce

Nuovo oggetto CompareInfo associato alle impostazioni cultura con l'identificatore specificato che usa i metodi di confronto tra stringhe nell'oggetto Assembly corrente.

Eccezioni

name è null.

name è un nome di impostazioni cultura non valido.

Esempio

Nell'esempio seguente vengono confrontate parti di due stringhe usando i diversi CompareInfo oggetti:

  • CompareInfo oggetto associato alla cultura spagnola (Spagna) con l'ordinamento internazionale

  • CompareInfo oggetto associato alla cultura spagnola (Spagna) con l'ordinamento tradizionale

  • CompareInfo oggetto associato all'oggetto InvariantCulture

C#
// The following code example compares two strings using the different CompareInfo instances:
//    a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
//    a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
//    a CompareInfo instance associated with the InvariantCulture.

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

*/

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

GetCompareInfo(Int32, Assembly)

Origine:
CompareInfo.cs
Origine:
CompareInfo.cs
Origine:
CompareInfo.cs

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura specificate e che usa i metodi di confronto tra stringhe nell'oggetto Assembly specificato.

C#
public static System.Globalization.CompareInfo GetCompareInfo (int culture, System.Reflection.Assembly assembly);

Parametri

culture
Int32

Intero che rappresenta l'identificatore di impostazioni cultura.

assembly
Assembly

Assembly che contiene i metodi di confronto tra stringhe da usare.

Restituisce

Nuovo oggetto CompareInfo associato alle impostazioni cultura con l'identificatore specificato che usa i metodi di confronto tra stringhe nell'oggetto Assembly corrente.

Eccezioni

assembly è null.

assembly è di un tipo non valido.

Commenti

Nota

Il comportamento di questo metodo è imprevedibile. È consigliabile che l'applicazione usi una versione di questo metodo che non accetta un input di assembly.

Il assembly parametro deve essere dello stesso tipo di Module.Assembly.

Vedi anche

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetCompareInfo(String, Assembly)

Origine:
CompareInfo.cs
Origine:
CompareInfo.cs
Origine:
CompareInfo.cs

Inizializza un nuovo oggetto CompareInfo associato alle impostazioni cultura specificate e che usa i metodi di confronto tra stringhe nell'oggetto Assembly specificato.

C#
public static System.Globalization.CompareInfo GetCompareInfo (string name, System.Reflection.Assembly assembly);

Parametri

name
String

Stringa che rappresenta il nome delle impostazioni cultura.

assembly
Assembly

Assembly che contiene i metodi di confronto tra stringhe da usare.

Restituisce

Nuovo oggetto CompareInfo associato alle impostazioni cultura con l'identificatore specificato che usa i metodi di confronto tra stringhe nell'oggetto Assembly corrente.

Eccezioni

name è null.

-oppure-

assembly è null.

name è un nome di impostazioni cultura non valido.

-oppure-

assembly è di un tipo non valido.

Commenti

Nota

Il comportamento di questo metodo è imprevedibile. È consigliabile usare una versione di questo metodo che non accetta un input dell'assembly.

Il assembly parametro deve essere dello stesso tipo di Module.Assembly.

Vedi anche

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1