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

C# Code: Sorting Strings without LINQ; System.Collections.Generic; String.Compare

using System; using System.Collections.Generic;

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

    l.Add(&quot;c12three&quot;);
    l.Add(String.Empty);
    l.Add(&quot;5six7&quot;);
    l.Add(&quot;_score&quot;);
    l.Add(&quot;zounds&quot;);
    l.Add(null);
    l.Add(&quot;#pound1&quot;);
    l.Add(&quot;#pound2&quot;);
    l.Add(&quot;apple&quot;);

    l.Sort(new Comparison&lt;string&gt;(SortByString));

    foreach(string s in l)
    {
        Console.WriteLine(s);
    }

    Program.ConsoleKey();
}

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

    Console.ReadKey(false);

}

private static int SortByString(string s1, string s2)
{
    return String.Compare(s1,s2);
}  

}

mod date: 2008-10-01T23:55:26.000Z