I have a problem on how to order a list.
I have a list of products and i sort them by price. But in my db i have two prices : price and offer.
I want to sort my products by price , BUT if offer is >0 then i want to sort by offer
I thought of this but it does not work:
list.OrderBy(p => p.offer != 0 ? p.offer : p.price );
Any ideas??
As someone has said,
OrderBydoesn’t sort in place. It returns aIOrderedEnumerable(it’s something similar to anIEnumerable, but ordered 🙂 ).If you want to sort in place (and you are using a
List<>) do this: