using System.Collections.Generic;
public static void Main(string[] args)
Dictionary<int, string> openWith = new Dictionary<int, string>();
openWith.Add(2, "notepad.exe");
openWith.Add(4, "paint.exe");
openWith.Add(6, "paint.exe");
openWith.Add(8, "wordpad.exe");
openWith.Add(8, "winword.exe");
catch (ArgumentException)
openWith[8] = "winword.exe";
openWith[9] = "winword.exe";
catch (KeyNotFoundException)
Console.WriteLine("Key = \"tif\" is not found.");
if (openWith.TryGetValue(2, out value))
Console.WriteLine("For key = 2, value = {0}.", value);
if (!openWith.ContainsKey(12))
openWith.Add(12, "hypertrm.exe");
Console.WriteLine("Value added for key = \"ht\": {0}",
foreach( KeyValuePair<int, string> kvp in openWith )
Console.WriteLine("Key = {0}, Value = {1}",
Dictionary<int, string>.ValueCollection valueColl =
foreach( string s in valueColl )
Console.WriteLine("Value = {0}", s);
Dictionary<int, string>.KeyCollection keyColl =
foreach( int s in keyColl )
Console.WriteLine("Key = {0}", s);
Console.WriteLine("\nRemove(\"doc\")");
if (!openWith.ContainsKey(4))
Console.WriteLine("Key \"doc\" is not found.");