例子2:
using System; public string Get() foreach (DictionaryEntry de in hashTable) System.Collections.IDictionaryEnumerator enumerator = hashTable.GetEnumerator(); return (string)hashTable[1];
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace GetSpec
{
class HashTableDemo
{
{
Hashtable hashTable = new Hashtable();
hashTable.Add(1, "wuyi");
hashTable.Add(2, "sky");
System.Windows.Forms.MessageBox.Show((string)hashTable[1]);
{
System.Windows.Forms.MessageBox.Show(de.Key.ToString());
System.Windows.Forms.MessageBox.Show(de.Value.ToString());
}
while (enumerator.MoveNext())
{
System.Windows.Forms.MessageBox.Show(enumerator.Key.ToString());
System.Windows.Forms.MessageBox.Show( enumerator.Value.ToString());
}
}
}
}
本文通过一个具体的示例展示了如何在C#中使用Hashtable进行键值对的存储与检索操作,并介绍了两种不同的遍历方法。
175

被折叠的 条评论
为什么被折叠?



