first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

C# Code: Sorting DateTime Values without LINQ Using a Delegate; System.Collections.Generic; DateTime.Compare

using System; using System.Collections.Generic;

class Program { static void Main(string[] args) { List<DateTime> l = new List<DateTime>();

    l.Add(new DateTime(2008, 2, 24, 11, 32, 15));
    l.Add(new DateTime(1808, 6, 12, 4, 0, 10));
    l.Add(new DateTime(1908, 2, 24, 11, 32, 15));
    l.Add(new DateTime(1945, 7, 6, 13, 0, 0));
    l.Add(new DateTime(1619, 2, 24, 23, 32, 15));

    l.Sort(new Comparison&lt;DateTime&gt;(
        delegate (DateTime d1, DateTime d2)
        { return DateTime.Compare(d1, d2); }));

    foreach(DateTime d in l)
    {
        Console.WriteLine(d);
    }

    Program.ConsoleKey();
}

static void ConsoleKey()
{
    Console.WriteLine(
        string.Format(&quot;{0}Press any key to continue...&quot;,
        Environment.NewLine));

    Console.ReadKey(false);

}

}

mod date: 2008-10-02T00:09:02.000Z