SortedList类中的数据如何按我自定义地排序

来源:互联网 发布:伯罗奔尼撒战争 知乎 编辑:程序博客网 时间:2024/04/30 09:39

      初始化 SortedList<TKey, TValue> 类的新实例,该实例为空且具有指定的初始容量,并使用指定的 IComparer<T>

 

命名空间:  System.Collections.Generic
程序集:  System(在 System.dll 中)

 

参数讲解:

capacity
类型:System.Int32
SortedList<TKey, TValue> 可包含的初始元素数。
comparer
类型:System.Collections.Generic.IComparer<TKey>
IComparer<T> 实现,对键进行比较时使用。
- 或 -
null,则为这类键使用默认的 Comparer<T>

      要让SortedList中的数据按我想要地去排序,就要自己定义一个IComparer类,并重载当中的public int Compare(object x,object y)方法。

实例:

运行结果: