您的位置:首页 > 编程语言 > C#

如何在C#中遍历hashtable?

2009-08-04 16:41 316 查看
例子2:


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace GetSpec
{
class HashTableDemo
{

public string Get()
{
Hashtable hashTable = new Hashtable();
hashTable.Add(1, "wuyi");
hashTable.Add(2, "sky");
System.Windows.Forms.MessageBox.Show((string)hashTable[1]);

foreach (DictionaryEntry de in hashTable)
{
System.Windows.Forms.MessageBox.Show(de.Key.ToString());
System.Windows.Forms.MessageBox.Show(de.Value.ToString());
}

System.Collections.IDictionaryEnumerator enumerator = hashTable.GetEnumerator();
while (enumerator.MoveNext())
{
System.Windows.Forms.MessageBox.Show(enumerator.Key.ToString());
System.Windows.Forms.MessageBox.Show( enumerator.Value.ToString());
}

return (string)hashTable[1];
}
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: