C# SortedList Remove
Description
SortedList Remove
removes the element with the specified
key from a SortedList object.
Syntax
SortedList.Remove
has the following syntax.
public virtual void Remove(
Object key
)
Parameters
SortedList.Remove
has the following parameters.
key
- The key of the element to remove.
Returns
SortedList.Remove
method returns
Example
The following code
uses the Remove()
method to remove a key from SortedList
.
using System;// w w w . java 2s . c o m
using System.Collections;
class MainClass
{
public static void Main()
{
SortedList mySortedList = new SortedList();
mySortedList.Add("NY", "New York");
mySortedList.Add("FL", "Florida");
mySortedList.Add("AL", "Alabama");
mySortedList.Add("WY", "Wyoming");
mySortedList.Add("CA", "California");
foreach (string myKey in mySortedList.Keys)
{
Console.WriteLine("myKey = " + myKey);
}
foreach(string myValue in mySortedList.Values)
{
Console.WriteLine("myValue = " + myValue);
}
Console.WriteLine("Removing FL from mySortedList");
mySortedList.Remove("FL");
}
}
The code above generates the following result.