//Dictionary<TKey,TValue> Dictionary<string,Model_driver> cur_driver = new Dictionary<string, Model_driver>(); if (cur_driver.ContainsKey(it.Name)) { ... }
SortedDictionary<TKey, TValue>
// Create a new dictionary of strings, with string keys. // Dictionary<string, string> openWith = new Dictionary<string, string>();
// If a key does not exist, setting the indexer for that key // adds a new key/value pair. openWith["doc"] = "winword.exe";
// Add some elements to the dictionary. There are no // duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe");
// The indexer can be used to change the value associated // with a key. openWith["rtf"] = "winword.exe";
// ContainsKey can be used to test keys before inserting // them. if (!openWith.ContainsKey("ht")) { openWith.Add("ht", "hypertrm.exe"); Console.WriteLine("Value added for key = \"ht\": {0}", openWith["ht"]); }
|