C# C# Console Application

How to remove all items from a Dictionary in C#1 min read

Dictionary Clear() Method: .Net framework dictionary Clear() method allow us to remove all keys and values from the Dictionary<TKey, TValue>. this Dictionary<TKey, TValue>.Clear() method exists under System.Collections.Generic namespace. this method has no optional or required parameter.

the Clear() method implements as ICollection<T>.Clear() and IDictionary.Clear(). this method set the Count property value to 0 (zero) but the Capacity remains unchanged.




the following c# example code demonstrate us how can we remove all elements from dictionary programmatically at run time in an console application.

Output:

How to remove all items from a Dictionary in C#

How to remove all items from a Dictionary in C#

Leave a Comment