本文整理汇总了C#中CultureInfo.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo.Compare方法的具体用法?C# CultureInfo.Compare怎么用?C# CultureInfo.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CultureInfo
的用法示例。
在下文中一共展示了CultureInfo.Compare方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareInfoBasicTests
public static void CompareInfoBasicTests()
{
string one = "A test string";
string aCopyOfOne = one;
StringComparer comp = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
Assert.Equal(0, comp.Compare(one, aCopyOfOne));
Assert.True(comp.Equals(one, aCopyOfOne));
Assert.Equal(-1, comp.Compare(null, one));
Assert.Equal(0, comp.Compare(null, null));
Assert.Equal(1, comp.Compare(one, null));
Assert.False(comp.Equals(null, one));
Assert.True(comp.Equals(null, null));
Assert.False(comp.Equals(one, null));
Assert.Equal(comp.GetHashCode("abc"), comp.GetHashCode("ABC"));
}
示例2: Compare
public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedWindows, int expectedICU)
{
int expected = s_isWindows ? expectedWindows : expectedICU;
StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options);
Assert.Equal(expected, Math.Sign(comparer.Compare(x, y)));
Assert.Equal((expected == 0), comparer.Equals(x, y));
if (x != null && y != null)
{
Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y)));
}
}
示例3: CompareVarying
private static void CompareVarying(string one, string two, int compareValue, string culture, CompareOptions compareOptions)
{
StringComparer comp = new CultureInfo(culture).CompareInfo.GetStringComparer(compareOptions);
Assert.Equal(compareValue, comp.Compare(one, two));
if (compareValue == 0)
{
Assert.True(comp.Equals(one, two));
}
else
{
Assert.False(comp.Equals(one, two));
}
}