If I have a List<T>
, I can sort it in place using for example
myList.Sort((x,y) => x.MyComparisonMethod(y));
If I have an IList<T>
, I can sort it into a new list using
var sortedIList = unsortedIList.OrderBy(x => x.SortingValue);
How can I sort an IList<T>
in place?
I am using C# .NET 4.5.1.
I suspect you're referring to the fact that your
OrderBy
won't compile. That's because it returns anIOrderedEnumerable
, which is not anIList
, you'd have to performToList()
afterwards to convert it back to anIList
implementation:And if you want to use your own
IComparer
: