我是靠谱客的博主 怕黑鸡翅,这篇文章主要介绍不排序和可以重复Key的SortedList,现在分享给大家,希望可以做个参考。


普通的SortedList会自动排序,下面实现不自动排序代码如下:

using System;
using System.Collections;

namespace testSortedList
{
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            SortedList sl = new SortedList(new MySort());        //不排序

            sl.Add(333, 333);
            sl.Add(111, 111);
            sl.Add(222, 222);
            sl.Add(111, 112);

            PrintList(sl);

            Console.ReadLine();
        }

        private static void PrintList(SortedList sl)
        {
            for (int i = 0; i < sl.Count; i++)
            {
                Console.WriteLine("{0}t{1}", sl.GetKey(i), sl.GetByIndex(i));
            }//end for

        }//end fn()


    }
    public class MySort : IComparer
    {
        #region IComparer 成员

        public int Compare(object x, object y)
        {
            return -1;

            //排序

//            int iResult = (int)x - (int)y;

//            if(iResult == 0) iResult = -1;

//            return iResult;


        }
        #endregion

    }
}



最后

以上就是怕黑鸡翅最近收集整理的关于不排序和可以重复Key的SortedList的全部内容,更多相关不排序和可以重复Key内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(132)

评论列表共有 0 条评论

立即
投稿
返回
顶部