C# SortedList Clear
Description
SortedList Clear
removes all elements from a SortedList
object.
Syntax
SortedList.Clear
has the following syntax.
public virtual void Clear()
Returns
SortedList.Clear
method returns
Example
The following code example shows how to clear the values of the SortedList.
using System;// w ww . j a va2 s. co m
using System.Collections;
public class SamplesSortedList {
public static void Main() {
SortedList mySL = new SortedList();
mySL.Add( "one", "1" );
mySL.Add( "two", "2" );
mySL.Add( "three", "3" );
Console.WriteLine( " Count : {0}", mySL.Count );
Console.WriteLine( " Capacity : {0}", mySL.Capacity );
mySL.Clear();
Console.WriteLine( " Count : {0}", mySL.Count );
Console.WriteLine( " Capacity : {0}", mySL.Capacity );
}
}
The code above generates the following result.