集合之HashTable

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
Hashtable ht
= new Hashtable();

ht.Add(
"first","One");

ht.Add(
"second", "Two");

ht.Add(
"third", "three");

ht.Add(
"forth", "fore");

printKeyAndValues(ht);

}

public static void printKeyAndValues(Hashtable ht)
{
foreach (string s in ht.Keys)//遍历键集合
{
Console.WriteLine(
"key : " + s);
}

foreach (string value in ht.Values)//遍历值集合
{
Console.WriteLine(
"value: " + value);
}

Console.WriteLine(
"---key ----value-----");

foreach (DictionaryEntry de in ht)//遍历键值对
{
Console.WriteLine(
"{0}:{1}",de.Key,de.Value);
}

}
}
}

posted on 2011-09-14 22:46  别人叫我军师  阅读(117)  评论(0编辑  收藏  举报