I need to sort in memory lists of strings or numbers in ascending or descending order. However, the list can contain null values and all null values must appear after the numbers or strings.
That is the input data might be:
1, 100, null, 5, 32.3
The ascending result would be
1, 5, 32.3, 100, null
The descending list would be
100, 32.3, 5, 1, null
Any ideas on how to make this work?
I don't have a compiler in front of me to check, but I'm thinking something like:
x.OrderBy(i => i == null).ThenBy(i => i)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With