【发布时间】:2012-05-04 12:04:25
【问题描述】:
有人能解释一下下面的代码return total ?? decimal.Zero吗?
public decimal GetTotal()
{
// Part Price * Count of parts sum all totals to get basket total
decimal? total = (from basketItems in db.Baskets
where basketItems.BasketId == ShoppingBasketId
select (int?)basketItems.Qty * basketItems.Part.Price).Sum();
return total ?? decimal.Zero;
}
是以下意思吗?
if (total !=null) return total;
else return 0;
【问题讨论】:
-
所以基于大约 10 个响应,我猜它被称为“null-coalescing operator”然后??? :p
标签: c# return-value null-coalescing-operator