I have the following query:
var ordersPlacedBeforeOneHourList = ordersPlacedBeforeOneHourAgo.Select(order => order.Promo.PercentOff * (double) order.TotalCost).ToList();
Some of my order.Promo.PercentOff
are null. How can I change the above line so that if order.Promo
is null, it behaves as if the values is 0
?
The idea is that if there is not a specific promotion applied, I will calculate the cost of the Promotion as 0 * order.TotalCost
(which will always be 0), and move on to the next values to calculate where orders.Promo
may not be null, and on down the line.
The null-coalescing operator is your friend.
(order.Promo.PercentOff ?? 0)
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