Javatpoint Logo
Javatpoint Logo

SortedDictionary.Clear() Method in C#

In this article, we will discuss about SortedDictionary.Clear() method in C#. A SortedDictionary is a general-purpose collection used to store key-value pairs in a sorted format, where the sorting is based on the key SortedDictionary is defined in the System.Collection.Generic namespace. This is dynamic, which means that the size of the sorted dictionary grows as needed.

What is SortedDictionary?

SortedDictionary requires keys to be unique. The use of duplicate keys is prohibited. In SortedDictionary, the keys are immutable and cannot be null. SortedDictionary allows values to be null if the value type is a reference type. It provides the fastest insert and delete operations on unsorted data. A SortedDictionary can only store key-value pairs of the same type. The capacity of a SortedDictionary is the number of key-value pairs that the SortedDictionary can hold.

The SortedDictionary.Clear() method removes all key-value pairs from the SortedDictionary.

Syntax:

It has the following syntax:

The below program will be used to describe the SortedDictionary.Clear() method :

Example 1:

Let us take an example to implement the SortedDictionary.clear() method in C#

Output:

The total number of key/value pairs in dict is: 8
The total pairs after the clear() method:
The total number of key/value pairs in dict is: 0

Example 2:

Let us take another example to implement the SortedDictionary.clear() method in C#

Output:

The total number of key/value pairs in dict is: 9
The total pairs after the clear() method:
The total number of key/value pairs in dict is : 0






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA




news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news