You can add multiple items in a Dictionary either using Add() method or during object creation (if all items are available).
If you want to add items in dictionary, you can either use Dictionary<tkey, tvalue>.Add() method or during object creation (if all items are available). If all items are not available, in that case you should use Add() method for the same.
Unfortunately we don't have AddRange() as there is no meaning of Range for associative container. Dictionary is an associative container.
Let's create an object of dictionary and add key, values in it during initialization.
Dictionary<int, string> dictionary = new Dictionary<int, string>()
{
{1, "Item one"},
{2, "Item two"}
};
You cannot add duplicate key in dictionary. Means you cannot write
dictionary.Add("one", "Value is one");
dictionary.Add("one", "Value is two");
The value in dictionary can be null for reference types but key cannot be null or duplicate.
You can use Add() method to add some items in dictionary.
Dictionary<int, string> dictionary = new Dictionary<int, string>();
dictionary.Add(1, "Item one");
dictionary.Add(1, "Item two");
Thanks for reading this article. Will write more soon...