[Mono-dev] Problem with List<T>.Sort(IComparer<T>)

Grant Monroe grant at janrain.com
Tue Dec 6 18:21:17 EST 2005


The following code results in an InvalidCastException rather than an
InvalidOperationExcepation wrapping the ApplicationException. I didn't
find any bug explicitly about this, but I just wanted make sure this
wasn't covered by another bug in bugzilla. If not, I'll go ahead and
post it.

using System;
using System.IO;
using System.Collections.Generic;

public class TestComparer: IComparer<string>
{
  public int Compare(string x, string y)
  {
      throw new ApplicationException("doesn't even get called");
  }
}

class Test
{
  public static void Main(string[] args)
  {
      List<string> l = new List<string>();
      l.Add("b");
      l.Add("a");
      l.Add("c");
      TestComparer sc = new TestComparer();
      l.Sort(sc);
  }
}



More information about the Mono-devel-list mailing list