-
C# hashTable的遍历【2种方法】与排序【3种方法】
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
Hashtable ht = new Hashtable();
-
-
ht.Add("job", "a");
-
ht.Add("jobmon", "20");
-
-
-
string a = ht["jobmon"].ToString();
-
-
-
-
foreach(DictionaryEntry de in ht)
-
{
-
Console.WriteLine(de.Key);
-
Console.WriteLine(de.Value);
-
}
-
-
Console.WriteLine("-------------------------");
-
-
-
IDictionaryEnumerator enumerator = ht.GetEnumerator();
-
while (enumerator.MoveNext())
-
{
-
Console.WriteLine(enumerator.Key);
-
Console.WriteLine(enumerator.Value);
-
}
-
-
Console.WriteLine("++++++++++++++++++++++++++");
-
-
-
ArrayList al = new ArrayList(ht.Keys);
-
-
al.Sort();
-
al.Reverse();
-
-
foreach (string str in al)
-
{
-
Console.WriteLine(str + " " + ht[str]);
-
}
-
-
Console.WriteLine("++++++++++++++++++++++++++");
-
-
-
ArrayList alv = new ArrayList(ht.Values);
-
alv.Sort();
-
-
foreach (string str in alv)
-
{
-
IDictionaryEnumerator enumerator2 = sl.GetEnumerator();
-
-
while (enumerator2.MoveNext())
-
{
-
if (str.Equals(enumerator2.Value.ToString()))
-
{
-
-
Console.WriteLine(enumerator2.Key + ":" + enumerator2.Value);
-
}
-
-
}
-
-
-
}
-
-
Console.WriteLine("++++++++++++++++++++++++++");
-
-
-
SortedList sl = new SortedList();
-
-
sl.Add("a", "a1");
-
sl.Add("c", "c1");
-
sl.Add("b", "b1");
-
-
IDictionaryEnumerator enumerator1 = sl.GetEnumerator();
-
while (enumerator1.MoveNext())
-
{
-
Console.WriteLine(enumerator1.Key);
-
Console.WriteLine(enumerator1.Value);
-
}
-
-
}
-
-
相关阅读:
Creative Cloud 无法连接问题
HTTP_PROXY
<video> controlsList
Electron 问题
含神经网络的离线AI翻译 APP
奠
(转载)移动Web开发技巧汇总
2014年总结
转载(web app变革之rem)
火狐不支持backgroundPosition的js插件
-
原文地址:https://www.cnblogs.com/lujiangping/p/10630036.html
Copyright © 2020-2023
润新知