当前位置: 首页>>代码示例>>C#>>正文


C# CaseInsensitiveComparer.Compare方法代码示例

本文整理汇总了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;
			}
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:33,代码来源:CaseInsensitiveComparerTest.cs

示例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);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:CaseInsensitiveComparerTest.cs

示例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"));
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:9,代码来源:CaseInsensitiveComparerTest.cs

示例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);
        }
开发者ID:uvbs,项目名称:Holodeck,代码行数:11,代码来源:ProcessListItemSorter.cs

示例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;
            }
        }
开发者ID:Breakpoint21,项目名称:backup.dh,代码行数:30,代码来源:ListViewColumnSorter.cs

示例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);
        }
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:7,代码来源:SWEDISHNAMECOMPARER.CS

示例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);
 }
开发者ID:huayang912,项目名称:cs-dotnetnuke,代码行数:7,代码来源:ListItemComparer.cs

示例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);
            }
        }
开发者ID:uvbs,项目名称:Holodeck,代码行数:16,代码来源:ProcessListItemSorter.cs

示例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);
 }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:7,代码来源:DualListControl.cs

示例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);
开发者ID:Tyelpion,项目名称:IronAHK,代码行数:67,代码来源:String.cs

示例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;
            }
开发者ID:tvmarinov,项目名称:Homework,代码行数:12,代码来源:SingingCats.cs

示例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);
 }
开发者ID:dasklub,项目名称:kommunity,代码行数:7,代码来源:Utilities.cs

示例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;
 }
开发者ID:BrianGoff,项目名称:BITS,代码行数:38,代码来源:DependencyFlowSplitterHelper.cs

示例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");
            }
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:44,代码来源:XmlPreprocessor.cs

示例15: Compare

 private int Compare(VersionEntity info1, VersionEntity info2)
 {
     int result;
     CaseInsensitiveComparer ObjectCompare = new CaseInsensitiveComparer();
     result = ObjectCompare.Compare(info1.BuildTime, info2.BuildTime);
     return result;
 }
开发者ID:panpeiphilo,项目名称:AutoUpdateDoNet2,代码行数:7,代码来源:UpdateSvc.asmx.cs


注:本文中的System.Collections.CaseInsensitiveComparer.Compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。