本文整理汇总了C#中System.Collections.CaseInsensitiveComparer.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# CaseInsensitiveComparer.Compare方法的具体用法?C# CaseInsensitiveComparer.Compare怎么用?C# CaseInsensitiveComparer.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.CaseInsensitiveComparer
的用法示例。
在下文中一共展示了CaseInsensitiveComparer.Compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCompare_Culture
public void TestCompare_Culture ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
// the default ctor is initialized using Thread.CurrentCulture
CaseInsensitiveComparer cic = new CaseInsensitiveComparer ();
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#A1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#A2");
// changing the current culture does not affect an already
// initialized CaseInsensitiveComparer
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#B1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#B2");
// but it does affect new instances
cic = new CaseInsensitiveComparer ();
Assert.AreEqual (0, cic.Compare ("I", "i"), "#C1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#C2");
// if the culture is explicitly set, then the thread culture is
// ignored
cic = new CaseInsensitiveComparer (new CultureInfo ("tr-TR"));
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#D1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#D2");
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
示例2: TestCompare
public void TestCompare () {
CaseInsensitiveComparer cic = new CaseInsensitiveComparer ();
AssertEquals(cic.Compare ("WILD WEST", "Wild West"),0);
AssertEquals(cic.Compare ("WILD WEST", "wild west"),0);
Assert(cic.Compare ("Zeus", "Mars") > 0);
Assert(cic.Compare ("Earth", "Venus") < 0);
}
示例3: TestCompare
public void TestCompare ()
{
CaseInsensitiveComparer cic = new CaseInsensitiveComparer ();
Assert.AreEqual (0, cic.Compare ("WILD WEST", "Wild West"));
Assert.AreEqual (0, cic.Compare ("WILD WEST", "wild west"));
Assert.AreEqual (1, cic.Compare ("Zeus", "Mars"));
Assert.AreEqual (-1, cic.Compare ("Earth", "Venus"));
}
示例4: CompareProcess
private int CompareProcess(object a, object b)
{
CaseInsensitiveComparer c = new CaseInsensitiveComparer();
if (Ascending)
{
return c.Compare(a, b);
}
return c.Compare(b, a);
}
示例5: Compare
public int Compare(object x, object y)
{
int ret;
ExplorerListItem first = x as ExplorerListItem;
ExplorerListItem second = y as ExplorerListItem;
if (ColumnToSort == 3)
{
ret = DateTime.Compare(DateTime.Parse(first.SubItems[ColumnToSort].Text), DateTime.Parse(second.SubItems[ColumnToSort].Text));
}
else
{
CaseInsensitiveComparer comp = new CaseInsensitiveComparer();
ret = comp.Compare(first.SubItems[ColumnToSort].Text, second.SubItems[ColumnToSort].Text);
}
if (SortingOrder == SortOrder.Ascending)
{
return ret;
}
else if(SortingOrder == SortOrder.Descending)
{
return (-ret);
}
else
{
return 0;
}
}
示例6: Compare
public int Compare(object x, object y)
{
CultureInfo ci = new CultureInfo("sv");
CaseInsensitiveComparer aComparer = null;
aComparer = new CaseInsensitiveComparer(ci);
return aComparer.Compare(x, y);
}
示例7: Compare
public virtual int Compare( object x, object y )
{
ListItem a = (ListItem)x;
ListItem b = (ListItem)y;
CaseInsensitiveComparer c = new CaseInsensitiveComparer();
return c.Compare(a.Text, b.Text);
}
示例8: Compare
public int Compare(object a, object b)
{
ListViewItem aItem = (ListViewItem)a;
ListViewItem bItem = (ListViewItem)b;
switch(columnToSort)
{
case 0:
return ComparePID(aItem.SubItems[0].Text, bItem.SubItems[0].Text);
case 1:
return CompareProcess(aItem.SubItems[1].Text, bItem.SubItems[1].Text);
default:
CaseInsensitiveComparer c = new CaseInsensitiveComparer();
return c.Compare(a, b);
}
}
示例9: Compare
public int Compare(object x, object y)
{
var a = (ListItem) x;
var b = (ListItem) y;
var c = new CaseInsensitiveComparer();
return c.Compare(a.Text, b.Text);
}
示例10: Sort
//.........这里部分代码省略.........
int sortAt = 1;
if (opts.ContainsKey('p'))
{
if (!int.TryParse(opts['p'], out sortAt))
sortAt = 1;
opts.Remove('p');
}
bool reverse = false, random = false;
if (opts.ContainsKey(Keyword_Random[0]))
{
if (opts[Keyword_Random[0]].Equals(Keyword_Random.Substring(1), StringComparison.OrdinalIgnoreCase)) // Random
random = true;
else
reverse = true;
opts.Remove(Keyword_Random[0]);
}
bool unique = false;
if (opts.ContainsKey('u'))
{
unique = true;
opts.Remove('u');
}
bool slash = false;
if (opts.ContainsKey('\\'))
{
slash = true;
opts.Remove('\\');
}
var comp = new CaseInsensitiveComparer();
var rand = new Random();
Array.Sort(list, delegate(string x, string y)
{
if (function != null)
{
object value = null;
try
{
value = function.Invoke(null, new object[] { new object[] { x, y } });
}
catch (Exception)
{
}
int result;
if (value is string && int.TryParse((string) value, out result))
return result;
return 0;
}
else if (x == y)
return 0;
else if (random)
return rand.Next(-1, 2);
else if (numeric)
{
int a, b;
return int.TryParse(x, out a) && int.TryParse(y, out b) ?
a.CompareTo(b) : x.CompareTo(y);
示例11: CaseInsensitiveComparer
int IComparer.Compare(Object x, Object y)
{
int[] xArray = (int[])x;
int[] yArray = (int[])y;
var myComp = new CaseInsensitiveComparer();
// X first -> Ascending, y first -> Descending
var toReturn = myComp.Compare(xArray.Sum(), yArray.Sum());
return toReturn;
}
示例12: Compare
public int Compare(object x, object y)
{
var lix = (ListItem) x;
var liy = (ListItem) y;
var c = new CaseInsensitiveComparer();
return c.Compare(lix.Text, liy.Text);
}
示例13: SimpleScalarValuesCompare
public static bool SimpleScalarValuesCompare(object _value1, object _value2, System.Type _unboxType, SimpleScalarValueCompareMode _compareMode)
{
bool result = false;
CaseInsensitiveComparer comparer = new CaseInsensitiveComparer();
//
switch (_compareMode)
{
case SimpleScalarValueCompareMode.Equal:
if (comparer.Compare(System.Convert.ChangeType(_value1, _unboxType),
System.Convert.ChangeType(_value2, _unboxType)) == 0)
result = true;
break;
case SimpleScalarValueCompareMode.LessThan:
if (comparer.Compare(System.Convert.ChangeType(_value1, _unboxType),
System.Convert.ChangeType(_value2, _unboxType)) < 0)
result = true;
break;
case SimpleScalarValueCompareMode.GreaterThan:
if (comparer.Compare(System.Convert.ChangeType(_value1, _unboxType),
System.Convert.ChangeType(_value2, _unboxType)) > 0)
result = true;
break;
case SimpleScalarValueCompareMode.LessThenOrEqual:
if (comparer.Compare(System.Convert.ChangeType(_value1, _unboxType),
System.Convert.ChangeType(_value2, _unboxType)) < 0)
result = true;
break;
case SimpleScalarValueCompareMode.GreaterThenOrEqual:
if (comparer.Compare(System.Convert.ChangeType(_value1, _unboxType),
System.Convert.ChangeType(_value2, _unboxType)) >= 0)
result = true;
break;
default:
break;
}
//
return result;
}
示例14: Evaluate
public override bool Evaluate(RuntimeValues runtimeEnv)
{
object leftVal = left.GetRuntimeValue(runtimeEnv);
object rightVal = right.GetRuntimeValue(runtimeEnv);
IComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture);
int compare;
if (leftVal is IComparable)
compare = comparer.Compare(leftVal, rightVal);
else if (rightVal is IComparable)
compare = -comparer.Compare(rightVal, leftVal);
else
{
// Only do this if neither version is comparable.
// The reason is IComparable objects can change the
// meaning of Equals in surprising ways if necessary,
// such as for version matching.
if (opToken == XppTokenType.EQ)
return Equals(leftVal, rightVal);
if (opToken == XppTokenType.NEQ)
return !Equals(leftVal, rightVal);
throw new ArgumentException("Can't perform a compare on two objects that don't implement IComparable");
}
switch (opToken)
{
case XppTokenType.LT:
return compare < 0;
case XppTokenType.LTE:
return compare <= 0;
case XppTokenType.EQ:
return compare == 0;
case XppTokenType.NEQ:
return compare != 0;
case XppTokenType.GT:
return compare > 0;
case XppTokenType.GTE:
return compare >= 0;
default:
throw new ArgumentException("Program error: Unexpected comparison operator in XppCompareExpr");
}
}
示例15: Compare
private int Compare(VersionEntity info1, VersionEntity info2)
{
int result;
CaseInsensitiveComparer ObjectCompare = new CaseInsensitiveComparer();
result = ObjectCompare.Compare(info1.BuildTime, info2.BuildTime);
return result;
}