Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value.
using System;
using System.Collections;
using System.Globalization;
public class SamplesSortedList
{
public static void Main()
{
SortedList mySL4 = new SortedList(StringComparer.InvariantCultureIgnoreCase);
Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):");
mySL4.Add("A", "a");
mySL4.Add("B", "b");
mySL4.Add("C", "c");
try
{
mySL4.Add("first", "Ola!");
}
catch (ArgumentException e)
{
Console.WriteLine(e);
}
PrintKeysAndValues(mySL4);
}
public static void PrintKeysAndValues(SortedList myList)
{
Console.WriteLine(" -KEY- -VALUE-");
for (int i = 0; i < myList.Count; i++)
{
Console.WriteLine(" {0,-6}: {1}",
myList.GetKey(i), myList.GetByIndex(i));
}
Console.WriteLine();
}
}
Related examples in the same category