Your ElementComparar is defined for the specific type QuestionElement, so downcasting it to the more generic type won't work.
This code should compile: List<QuestionElement> _items; public Set(T list) { _items = new List<QuestionElement>(); //code to load collection ElementComparer comparer = new ElementComparer(); _items.Sort(comparer); //WON'T COMPILE } -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Paul Cowan Sent: Wednesday, January 25, 2006 13:49 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: [ADVANCED-DOTNET] Generics Comiler error/headache I am trying to do a custom sort on using the following comparer: public class ElementComparer : IComparer<QuestionElement> { public int Compare(QuestionElement x, QuestionElement y) { return (x.Index > y.Index) ? 1 : (x.Index < y.Index) ? -1 : 0; } } I have the following code in the constructor of another object: Then in the constructor of another class, I am trying to sort on a List<U> like this: public Set(T list) { _items = new List<U>(); //code to load collection ElementComparer comparer = new ElementComparer(); _items.Sort(comparer); //WON'T COMPILE } The compiler error is cannot convert ElementComparer to IComparer<U>. What am I doing wrong. Thanks Paul =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com