What is the difference between dictionary and hashtable




















When we retrieve the items from Dictionary we will get the records in the same order we have inserted them. Whereas we add same records in Hashtable the order is not maintained. From the following example you can see the difference in the order of retrieval. A Dictionary class is a data structure that represents a collection of keys and values pair of data. The key is identical in a key-value pair and it can have at most one value in the dictionary, but a value can be associated with many different keys.

More about C Dictionary Iterate over a Dictionary. There are many different ways to iterate over a Dictionary in C. From the following link you can see in detail Both lists and dictionaries are used to store collections of data. How to sort an array in C? How to sort object array by specific property in C? How to read file using StreamReader in C? Difference between delegates and events in C How to sort the generic SortedList in the descending order? How to write file using StreamWriter in C?

Hashtable Dictionary Hashtable is included in the System. Collections namespace. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Difference between Dictionary and Hashtable [duplicate] Ask Question. Asked 12 years, 6 months ago. Active 4 years, 1 month ago. Viewed k times. Improve this question. Community Bot 1 1 1 silver badge.

It seems that this question should be closed as a duplicate, and its answers merged with one of the duplicates.

Although related to java language but this thread is worth reading to know the difference between HashMap and HashTable. Few differences apply to C world also. Add a comment. Active Oldest Votes.

Improve this answer. Gabe Marc Gravell Marc Gravell k gold badges silver badges bronze badges. But Dictionary's instance methods aren't thread-safe, unlike the Hashtable — t3mujin. Lets give an example that would explain the difference between hashtable and dictionary. Add 2. ToString ; lblDisplay2. ToString ; lblDisplay3. ToString ; lblDisplay4.

Add "cat", 2 ; dictionary. Add "dog", 1 ; dictionary. Add "llama", 0 ; dictionary. Pritom Nandy Pritom Nandy 1, 9 9 silver badges 5 5 bronze badges. As a note I guess one is direct while the other isn't. Hash functions may not be perfect either and may sometimes provide an index referencing the wrong value. But that can be corrected. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more. What is the difference between a hash and a dictionary? Ask Question. Asked 10 years, 10 months ago. Active 3 years, 8 months ago. Viewed 54k times. What is the difference between Hash and Dictionary? Improve this question.



0コメント

  • 1000 / 1000