Sort array by delegate <p>I want to sort an array alphabetically using a delegate. The input is</p> <pre><code>"m", "a", "d", "f", "h" </code></pre> <p>but the output is</p> <pre><code> a a d f h </code></pre> <p>i.e. it is ordered alphabetically but the "m" is missing and with "a" doubled. What is the reason?</p> <p>Source code:</p> <pre><code>class ArrayMethods { public void sort(String[] array, t xcompare) { xcompare = compare; for (int i = 0; i &lt; array.Length - 1 ; i++) { array[i] = xcompare(array[i], array[i + 1]); } foreach (var a in array) { Console.WriteLine(a); } } public String compare(string p, string x) { string result = ""; if (String.Compare(p, x) &lt; 0) { result = p; } else { result = x; } return result; } } public delegate string t(string firstString, string secondString); class Program { public static string[] names = { "m", "a", "d", "f", "h" }; static void Main(string[] args) { ArrayMethods arrayMethods = new ArrayMethods(); t delHandler = null; arrayMethods.sort(names, delHandler); Console.ReadKey(); } } </code></pre>