keys可重复的字典
来源:互联网 发布:传智播客 java简历 编辑:程序博客网 时间:2024/05/18 02:16
众所周知,C#Dictionary中的keys 是不允许重复的。以前在程序中使用了Dictionary,结果今天客户要求keys 可以重复。所以为了简单只好找个可重复的Dictionary-->SortedList:SortedList 对象包含用键/值对表示的项目。SortedList 对象可按照字符顺序或数字顺序自动地对项目进行排序。根据SortedList 对象排序的特性课巧妙的让它的key是可重复。代码如下:
public class MySort : IComparer
{
public int Compare(object x, object y)
{
return -1;
}
}
SortedList mySortedList = new SortedList(new MySort());
mySortedList.Add(333, 333);
mySortedList.Add(111, 111);
mySortedList.Add(222, 222);
mySortedList.Add(111, 112);
//遍历SortedList方法(1)
for (int i = 0; i < mySortedList.Count; i++)
{
System.Console.WriteLine(mySortedList.GetKey(i));
System.Console.WriteLine(mySortedList.GetByIndex(i));
}
System.Console.WriteLine("\n");
//遍历SortedList方法(2)
foreach (DictionaryEntry de in mySortedList)
{
System.Console.WriteLine(de.Key);
System.Console.WriteLine(de.Value);
}
- keys可重复的字典
- 确定任意可重复集合某一排列的字典序
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values(),时间类型处理
- 关于GridView控件中Keys,NewValues,OldValues字典的问题
- python中字典keys,values,items的使用
- 字典列表 统计重复字典的数量
- 对字符串求字典序全排列(字符可重复)
- 字典中items(),keys(),values()
- 可重复覆盖的DLX
- Python的字典的items(), keys(), values()都返回一个list
- 去除列表中重复的字典
- 判断字典中keys是不是存在
- Python中的字典方法:items(),get(),keys()
- Object.keys(obj)返回参数obj可被枚举的属性
- Lucene 简单小例子
- SQL存储过程中SQL语句拼接
- NYOJ 647 奋斗小蜗牛在请客【模拟】
- 说说加密与解密这对冤家 一
- 从大小为n的数组中取出m个数的组合
- keys可重复的字典
- 今天看到一篇介绍环形消息队列的文章,学习了
- MD5加密认证问题
- 自己动手写搜索引擎(常搜吧历程五#解析文档之XML#)(Java、Lucene、hadoop)
- uC/OS-II 学习笔记之:消息邮箱
- 简单工厂、工厂方法与抽象工厂模式对比
- 帮助你实现移动设备上的拖拽刷新功能的javascript类库 - hook.js
- control cleared invoice can't be cancelled
- http 简记