How does a dictionary maintain data?
A dictionary uses linked lists to data. Consider you are using a generic dictionary<string, ‘AnyType’>. A dictionary sorts and searches data based on the key which will be difficult to sort on string type.
How does dictionary perform these operations so quickly?
Well, quite simple. It uses a hash code. Dictionary converts the key value into its corresponding hash code and stores only that hash code. Now searching and sorting on hash code becomes faster.
How does it do it, practically?
Just like linked list, let’s create a Node class. To understand following code better, I would say please go and watch how linked list is implemented here
- namespace Generic
- {
- public class Node<T>
- {
- public T data;
- public Node(T data)
- {
- this.data = data;
- }
- }
- }
Now to maintain a key value pair and to link the objects, we need to create another class.
- namespace Generic
- {
- public class HashNodeMap<T>
- {
- public int key;
- public Node<T> data;
- public HashNodeMap<T> next;
- }
- }


Mehdi GhomshePosted May 25, 2021, 8:36 PM
Can you tell me how can I implement a ContainsKey() method in this custom dictionary?