Problem comparing items implementing IComparable?

IComparable doesn't (and can't) say anything about operators. You should be using: if (current. CompareTo(min) .

Default as Marc suggested. ) Some other comments about your method: If all of the key values are more than the default value for K (e.g. K=int and all the keys are positive) then you won't find an item You may wish to have an overload which accepts a particular IComparareWhat if I wanted to find the person with the lexicographically earliest name? If there are no elements, it will return the default value for T to fit in with the rest of LINQ I would suggest throwing InvalidOperationException I would suggest using TSource and TKey as the type parameters to be more consistent with LINQ You may want to look at the MoreLINQ MinBy implementation as an alternative.

(Looking over that again, I'm not sure it's a good idea for us to require that comparer is non-null; it should probably use the default comparer in the same way as normal LINQ does if the comparer is null.).

IComparable doesn't (and can't) say anything about operators. You should be using: if (current. CompareTo(min) instead.(Or drop the constraint and just use Comparer.

Default as Marc suggested. ) Some other comments about your method: If all of the key values are more than the default value for K (e.g. K=int and all the keys are positive) then you won't find an item You may wish to have an overload which accepts a particular IComparare (but only if you drop the comparable constraint) There's no real need to constrain K to a value type. What if I wanted to find the person with the lexicographically earliest name?

If there are no elements, it will return the default value for T; to fit in with the rest of LINQ I would suggest throwing InvalidOperationException I would suggest using TSource and TKey as the type parameters to be more consistent with LINQ You may want to look at the MoreLINQ MinBy implementation as an alternative.(Looking over that again, I'm not sure it's a good idea for us to require that comparer is non-null; it should probably use the default comparer in the same way as normal LINQ does if the comparer is null. ).

Thanks Jon.. I got it :) – RameshVel Feb 24 at 6:59 Yeah you are right.. I should consider all these points... – RameshVel Feb 24 at 7:09.

IComparable doesn't provide operator support - you need to use current. CompareTo(min). Or better, use Comparer.Default.

Compare(current,min) - then you can drop the constraint and it'll handle nulls etc automatically, and it'll avoid boxing. Var comparer = Comparer. Default; ... // loop if(comparer.

Compare(current, min).

Thanks Marc, thats a nice trick.. :) – RameshVel Feb 24 at 7:03.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions