集合之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);
}
}
}
}
写的是不难,难的是天天坚持写!