This is a discussion on Using Dictionary in C# within the C# Programming forums, part of the Software Development category; Hi, I want to give a brief explanation about Dictionary class in Generic namespace. The Dictionary generic class provides a ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, I want to give a brief explanation about Dictionary class in Generic namespace. The Dictionary generic class provides a mapping from a set of keys to a set of values. Each addition to the dictionary consists of a value and its associated key. Retrieving a value by using its key is very fast, close to O(1), because the Dictionary class is implemented as a hash table. As long as an object is used as a key in the Dictionary, it must not change in any way that affects its hash value. Every key in a Dictionary must be unique according to the dictionary's equality comparer. A key cannot be a null reference (Nothing in Visual Basic), but a value can be, if the value type TValue is a reference type.
__________________ S.Balasubramanian Nothing is impossible |
| Sponsored Links |
| |||
| Syntax: Dictionary<key, value> sampleDictionary = new Dictionary<key, value>; As elements are added to a Dictionary, the capacity is automatically increased as required by reallocating the internal array. Type Parameters TKey The type of the keys in the dictionary. TValue The type of the values in the dictionary.
__________________ S.Balasubramanian Nothing is impossible |
| |||
| EX: Dictionary<string, string> dictionary = new Dictionary<string, string>(); // Add some elements to the dictionary. There are no // duplicate keys, but some of the values are duplicates. dictionary .Add("txt", "notepad.exe"); dictionary .Add("bmp", "paint.exe"); dictionary .Add("dib", "paint.exe"); dictionary .Add("rtf", "wordpad.exe"); // The Add method throws an exception if the new key is // already in the dictionary. try { dictionary .Add("txt", "winword.exe"); } catch (ArgumentException) { MessageBox.Show("An element with Key = " +txt+ " already exists."); } If you try to add a key value as duplicate, an exception is raised.
__________________ S.Balasubramanian Nothing is impossible |
| |||
| hi , The type System.Collections.Hashtable is not supported because it implements IDictionary. did u used the Hashtable in Webservice ...it causes error..Did u know....about that... Last edited by kingmaker : 12-24-2007 at 02:07 AM. |
| |||
|
__________________ The MOSS Master of Solution Service |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get the value in the dictionary both Key and Value collections simultaneously? | oxygen | C# Programming | 1 | 07-26-2007 08:00 AM |
| data dictionary views | sivakumar | Database Support | 1 | 07-18-2007 10:42 PM |
| What is the Dictionary class | vadivelanvaidyanathan | Java Programming | 1 | 07-17-2007 05:59 AM |