Add an element with the specified key and value to a SortedList in CSharp
Description
The following code shows how to add an element with the specified key and value to a SortedList.
Example
using System;// www. j a v a 2s . c o m
using System.Collections;
using System.Globalization;
public class SamplesSortedList
{
public static void Main()
{
SortedList mySL4 = new SortedList(StringComparer.InvariantCultureIgnoreCase, 3);
Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):");
mySL4.Add("FIRST", "Hello");
mySL4.Add("SECOND", "World");
mySL4.Add("THIRD", "!");
mySL4.Add("first", "Ola!");
for (int i = 0; i < mySL4.Count; i++)
{
Console.WriteLine("{0,-6}: {1}",mySL4.GetKey(i), mySL4.GetByIndex(i));
}
}
}
The code above generates the following result.