Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OrderBy and OrderByDescending are stable?

I am currently reading Pro LINQ c# 2008, and in page 87 the guy says OrderBy and OrderByDescending are stable. But he says exactly the opposite in page 96. It looks to me as he is referring to exactly the same functions, so I don't get it. Are they stable or not?

like image 505
devoured elysium Avatar asked Jul 30 '09 23:07

devoured elysium


People also ask

What is OrderBy in C#?

In a query expression, the orderby clause causes the returned sequence or subsequence (group) to be sorted in either ascending or descending order. Multiple keys can be specified in order to perform one or more secondary sort operations. The sorting is performed by the default comparer for the type of the element.

What is OrderBy in LINQ?

Sorts the elements of a sequence in ascending order according to a key. OrderBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>) Sorts the elements of a sequence in ascending order by using a specified comparer.

How do I use ascending order in LINQ?

In LINQ, the OrderBy operator is used to sort the list/ collection values in ascending order. In LINQ, if we use order by the operator by default, it will sort the list of values in ascending order. We don't need to add any ascending condition in the query statement.


1 Answers

Yes, they're definitely stable. I picked up the same error in my review of the book.

Joe responded to that bit of my review with this:

Just for your reader's knowledge, the ordering is now specified to be stable. Initially it was unstable, and was later changed to be stable but I was told it would be specified to be unstable, but apparently at some point, the specification was changed to be stable. My book was updated but apparently I missed a spot.

So yes, it was a mistake.

Overall it's a reasonably accurate book. (There are a few inaccuracies which are due to MSDN being inaccurate, but that's fairly easy to forgive.) There are far worse around :)

like image 187
Jon Skeet Avatar answered Oct 06 '22 00:10

Jon Skeet