Dictionarynames = new Dictionary (); names.Add(1, "John"); names.Add(2, "Mary"); names.Clear(); // Clears all the key-value pairs from the dictionary
DictionaryIn both examples, the Clear() method is called on the dictionary object to remove all the key-value pairs. Package Library: The System.Collections.Generic namespace is part of the .NET Framework Class Library.ages = new Dictionary (); ages["John"] = 25; ages["Mary"] = 30; ages.Clear(); // Clears all the key-value pairs from the dictionary