Toolroom Tech Blog

Devlopers Digest

Linq: Order by Null last

How to order null elements to the bottom with Linq

Sometimes you might to order values, where Null values should go to the bottom of the result. To achieve this, just use the following:

myObjects.OrderBy(_ => _.Value == null).ThenBy(_ => _.Value);