c#遍历HashTable

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];
        }
    }
}

posted on 2008-09-02 13:25  无意  阅读(42579)  评论(0编辑  收藏  举报

导航