How do I apply a default IComparable<T> in a Linq OrderBy clause

Viewed 2660

I have a type which has a default sort order as it implements IComparable<T> and IComparable. I'm not getting the results I expect from LINQ , basically it looks as if the IComparable<T> which the type implements is not being applied.

I thought I would get the result I want with an expression in the form:

var result = MyEnumerable<T>.OrderBy(r => r); 

where T itself implements IComparable<T>. It's not happening.

I can see related questions where specific IComparable<T> classes are specified for the sort, but I can't find one which uses the default IComparable<T> implemented by T itself.

My syntax is clearly incorrect. What is the correct syntax please?

Thanks in advance.

2 Answers
Related