C#语法一些简化备忘

有些传统的写法,可以简写,之前没留意到,现在才注意到

IDE0031: Null check can be simplified 

 entity.Unit = entity.Unit == null ? null : entity.Unit.Trim();

可以改成

 entity.Unit = entity.Unit?.Trim();


IDE0029 可以简化 Null 检查。 

c.DeedTaxStatus==null?"未缴清": c.DeedTaxStatus,

可以改成    如果 ?? 运算符的左操作数非空,该运算符将返回左操作数,否则返回右操作数。

c.DeedTaxStatus ?? "未缴清"

IDE0037 member name can be simplified

            var results = new { smsCode = smsCode };

可以改成

            var results = new { smsCode };
原文地址:https://www.cnblogs.com/zitjubiz/p/10972924.html