using System;
using System.Collections;
namespace P7_5
{
    class Program
    {
        static void Main()
        {
            //һϣopenWith
            Hashtable openWith = new Hashtable();
            // һЩԪֵϣСԪвظļظֵ
            openWith.Add("txt", "notepad.exe");
            openWith.Add("bmp", "paint.exe");
            openWith.Add("dib", "paint.exe");
            openWith.Add("rtf", "wordpad.exe");
            // ڹϣѾڵļAddӻִ
            try
            {
                openWith.Add("txt", "winword.exe");
            }
            catch
            {
                Console.WriteLine(" Key = \"txt\" ԪѾڡ");
            }
            //ֵͨԪ
            Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
            // ͨ޸ֵ
            openWith["rtf"] = "winword.exe";
            Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
            //ͨ޸ֵʱԶӼ/ֵ
            openWith["doc"] = "winword.exe";
            //ֵͨʱᱨ
            try
            {
                Console.WriteLine("For key = \"tif\", value = {0}.", openWith["tif"]);
            }
            catch
            {
                Console.WriteLine("Key = \"tif\" ûз");
            }
            // ڲ/ֵ֮ǰʹContainsKeyԸüǷ
            if (!openWith.ContainsKey("ht"))
            {
                openWith.Add("ht", "hypertrm.exe");
                Console.WriteLine("ֵkey = \"ht\": {0}", openWith["ht"]);
            }
            //ʹforeachöٹϣԪ
            Console.WriteLine();
            foreach (DictionaryEntry de in openWith)
            {
                Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
            }
            // ֵʹֵ
            ICollection valueColl = openWith.Values;
            //ֵֵ
            Console.WriteLine();
            foreach (string s in valueColl)
            {
                Console.WriteLine("Value = {0}", s);
            }
            // üʹü
            ICollection keyColl = openWith.Keys;
            // ֵ
            Console.WriteLine();
            foreach (string s in keyColl)
            {
                Console.WriteLine("Key = {0}", s);
            }
            // Removeм/ֵ
            Console.WriteLine("\nRemove(\"doc\")");
            openWith.Remove("doc");
            if (!openWith.ContainsKey("doc"))
            {
                Console.WriteLine("Key \"doc\" ûз֡");
            }
             Console.ReadLine();
        }
    }
}
