c#这条线是什么意思?
发布时间:2020-12-15 20:49:03 所属栏目:百科 来源:网络整理
导读:可以有人解释下面的代码返回总数??十进制.你好吗? 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 se
可以有人解释下面的代码返回总数??十进制.你好吗?
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; 解决方法
是的,这就是它的含义.它被称为
null-coalescing operator.
它只是一个语法快捷方式.但是,它可以更有效,因为读取的值仅评估一次. (注意,在两次评估值有副作用的情况下,也可能存在功能差异.) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |