Let's say I have the following list:
var someList = new List<SomeObject>();
Which has the following entries:
SomeObject.Field
Apple
Orange
FruitBowl_Outside
Banana
Grape
FruitBowl_Inside
I would like to sort this list so that FruitBowl entries go at the bottom, and that subject to this, everything is alphabetic.
In order words:
SomeObject.Field
Apple
Banana
Grape
Orange
FruitBowl_Inside
FruitBowl_Outside
                You can use the OrderBy() and ThenBy() methods:
var orderedList = someList.OrderBy(obj => obj.Field.StartsWith("FruitBowl_"))
                          .ThenBy(obj => obj.Field);
                        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