Create empty SortedList and element sorted by IComparable implemented by each key in CSharp

Description

The following code shows how to create empty SortedList and element sorted by IComparable implemented by each key.

Example


using System;/* w  w w .ja v a2  s. c o 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 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