本文整理汇总了C#中System.Globalization.CompareInfo.GetCompareInfo方法的典型用法代码示例。如果您正苦于以下问题:C# CompareInfo.GetCompareInfo方法的具体用法?C# CompareInfo.GetCompareInfo怎么用?C# CompareInfo.GetCompareInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.CompareInfo
的用法示例。
在下文中一共展示了CompareInfo.GetCompareInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
// 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 ) );
}
}
输出:
Comparing "calle" and "calor" With myCompIntl.Compare: -1 With myCompTrad.Compare: 1 With myCompInva.Compare: -1