CompareInfo::GetCompareInfo Method (Int32)
Initializes a new CompareInfo object that is associated with the culture with the specified identifier.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- culture
- Type: System::Int32
An integer representing the culture identifier.
Return Value
Type: System.Globalization::CompareInfoA new CompareInfo object associated with the culture with the specified identifier and using string comparison methods in the current Assembly.
If a security decision depends on a string comparison or a case change, the application should use the InvariantCulture to ensure that the behavior is consistent regardless of the culture settings of the operating system.
The following code example compares portions of two strings using the different CompareInfo objects:
CompareInfo object associated with the Spanish (Spain) culture with international sort
CompareInfo object associated with the Spanish (Spain) culture with traditional sort
CompareInfo object associated with the InvariantCulture
// The following code example compares two strings using the different CompareInfo instances: // a CompareInfo instance associated with the S"Spanish - Spain" culture with international sort, // a CompareInfo instance associated with the S"Spanish - Spain" culture with traditional sort, and // a CompareInfo instance associated with the InvariantCulture. using namespace System; using namespace System::Globalization; int main() { // Defines the strings to compare. String^ myStr1 = "calle"; String^ myStr2 = "calor"; // Uses GetCompareInfo to create the CompareInfo that // uses the S"es-ES" culture with international sort. CompareInfo^ myCompIntl = CompareInfo::GetCompareInfo( "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( "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 */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.