Create SortedList with specified capacity and IComparer in CSharp

Description

The following code shows how to create SortedList with specified capacity and IComparer.

Example


using System;//www  .  j  a  v  a 2 s .  c  om
using System.Collections;
using System.Globalization;

public class SamplesSortedList
{
    public static void Main()
    {
        CultureInfo myCul = new CultureInfo("tr-TR");
        SortedList mySL3 = new SortedList(new CaseInsensitiveComparer(myCul), 3);

        mySL3.Add("FIRST", "Hello");
        mySL3.Add("SECOND", "World");
        mySL3.Add("THIRD", "!");

        mySL3.Add("first", "Ola!");

        for (int i = 0; i < mySL3.Count; i++)
        {
            Console.WriteLine("{0,-6}: {1}",mySL3.GetKey(i), mySL3.GetByIndex(i));
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary