list sorted c# code example

Example 1: C# order a sorted list by key

SortedList<string,bool> l = new SortedList<string, bool>();
        l.Add("a", true);
        l.Add("b", false);
        l.Add("c", true);
        l.Add("d", false);
        var orderByVal = l.OrderBy(kvp => kvp.Key);

Example 2: c# sort list

using System;

class Program
{
    static void Main()
    {
        string[] colors = new string[]
        {
            "orange",
            "blue",
            "yellow",
            "aqua",
            "red"
        };
        // Call Array.Sort method.
        Array.Sort(colors);
        foreach (string color in colors)
        {
            Console.WriteLine(color);
        }
    }
}

Tags:

Misc Example