SortedList

In this chapter you will learn:

  1. SortedList and key/value pair

Using SortedList

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

using System;/* j ava2  s. c  om*/
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:

Next chapter...

What you will learn in the next chapter:

  1. How to check if a value is contained in SortedList