List<T>.Sort() method has 3 overloads.
One of them is the following
System.Collections.Generic.List<T>.Sort(System.Comparison<T>)
On seeing Comparison<T>, I thought that it should be a class which is derived from Comparison<T> class. (An usual interpretation on the parameters)
But the following works really well and said to be using the above overload.
public static void Main(string[] args)
{
List<Int32> collection = new List<Int32>();
collection.Add(20);
collection.Add(270);
collection.Add(30);
collection.Add(90);
collection.Add(40);
collection.Add(18);
collection.Add(100);
collection.Sort(MyComparer.CompareWithCase);
foreach (Int32 s in collection)
Console.WriteLine(s);
}
public static int CompareWithCase(int i1, int i2)
{
return i1.ToString().CompareTo(i2.ToString());
}
I did give a delegate to a static Method in place of Comparison<T>.
How does it work?