Edit

Share via


OrderedDictionary.Clear Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Removes all elements from the OrderedDictionary collection.

public void Clear();

Implements

Exceptions

The OrderedDictionary collection is read-only.

Examples

The following code example demonstrates the modification of an OrderedDictionary collection. In this example, the Clear method is used to empty the OrderedDictionary, and then the OrderedDictionary is repopulated. This code is part of a larger code example that can be viewed at OrderedDictionary.

// Clear the OrderedDictionary and add new values
myOrderedDictionary.Clear();
myOrderedDictionary.Add("newKey1", "newValue1");
myOrderedDictionary.Add("newKey2", "newValue2");
myOrderedDictionary.Add("newKey3", "newValue3");

// Display the contents of the "new" Dictionary using an enumerator
IDictionaryEnumerator myEnumerator =
    myOrderedDictionary.GetEnumerator();

Console.WriteLine(
    "{0}Displaying the entries of a \"new\" OrderedDictionary.",
    Environment.NewLine);

DisplayEnumerator(myEnumerator);

Remarks

After calling the Clear method, the Count property is set to zero and references to other objects from elements of the collection are also released. The capacity is not changed as a result of calling this method.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0