C# – Sort all but first element (Linq)

To sort a list, except for the first element, you need to: This can be accomplished in a single line using Linq methods: Example – sorting a list of people Let’s say we have a list of people, such as the following: Here’s how to sort the people by first name, except for the first … Read more

C# – How to sort by multiple fields (Linq)

Use the OrderBy() and ThenBy() Linq methods when you want to sort by multiple fields, like this: Ascending vs Descending order By default, OrderBy() and ThenBy() sort in ascending order. If you want to sort by descending order, use the Descending version of each method. For example, if I want to sort NFL teams within … Read more

Multithreaded quicksort in C#

One day I decided to challenge myself by trying to implement multithreaded quicksort. I wanted to see how it would compare to the built-in sort function – Array.Sort(). I came up with two algorithms that were 2-4x faster than Array.Sort(): After continuing to tinker, in attempts to further optimize, I came across PLINQ.AsParallel().OrderBy(). After reading … Read more