C# SortedList SortedList()

Description

SortedList SortedList() initializes a new instance of the SortedList class that is empty, has the default initial capacity, and is sorted according to the IComparable interface implemented by each key added to the SortedList object.

Syntax

SortedList.SortedList() has the following syntax.


public SortedList()

Example

SortedList is a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.


using System;/*from w ww. ja v  a 2  s  . co  m*/
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
class Sample
{
    public static void Main()
    {
        var sorted = new SortedList<string, MethodInfo>();

        foreach (MethodInfo m in typeof(object).GetMethods())
            sorted[m.Name] = m;

        foreach (string name in sorted.Keys) Console.WriteLine(name);

        foreach (MethodInfo m in sorted.Values)
            Console.WriteLine(m.Name + " returns a " + m.ReturnType);

    }

}

The output:





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack