Hashtable排序数据 [英] Hashtable sorting data

查看:99
本文介绍了Hashtable排序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做这样的hastable



Hashtable Al = new Hashtable();

Al.Add(C100, Carolla);

Al.Add(C200,BMW);

Al.Add(C300,Aulto);

Al.Add(C400,Civic);



,其输出为:



C100,Carolla

C200,宝马

C300,Aulto

C400,思域



和我想这样排序或者



C300,Aulto

C200,宝马

C400,Civic

C100,Carolla



plz帮我

i make a hastable like this

Hashtable Al = new Hashtable();
Al.Add("C100", "Carolla");
Al.Add("C200", "BMW");
Al.Add("C300", "Aulto");
Al.Add("C400", "Civic");

and its output is:

C100, Carolla
C200, BMW
C300, Aulto
C400, Civic

and i want to sorting like this or else

C300, Aulto
C200, BMW
C400, Civic
C100, Carolla

plz help me

推荐答案

Hashtable Al = new Hashtable();
Al.Add("C100", "Carolla");
Al.Add("C200", "BMW");
Al.Add("C300", "Aulto");
Al.Add("C400", "Civic");

List<string> cars = new List<string>(Al.Values);
cars.Sort();


存在用于将键映射到值的哈希表。该映射中隐含的是密钥不以任何特定顺序排序或存储的概念。所以没有办法按价值对Hashtable进行排序。



使用排序字典 [ ^ ],替代方案是迭代Hashtable并从中构造一个新的,已排序的对象。
Hashtables exist to map keys to values. Implicit in this mapping is the concept that the keys aren''t sorted or stored in any particular order. So there is no way to sort a Hashtable by Value.

You would probably be better off using a SortedDictionary[^] instead, as the alternative is to iterate the Hashtable and construct a new, sorted object from it.


看看这个..

排序哈希表 [ ^ ]
have a look at this..
Sorting Hashtable[^]


这篇关于Hashtable排序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆