OrderBy and OrderByDescending are stable?

devoured elysium picture devoured elysium · Jul 31, 2009 · Viewed 9.1k times · Source

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?

Answer

Jon Skeet picture Jon Skeet · Jul 31, 2009

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 :)