在if / else中使用null传播

时间:2018-03-09 00:04:36

标签: .net

enter image description here

这个resharper建议对此意味着什么? 如果grid为null,我想返回null。 变量“grid”是Selenium framework的IWebElement类型

1 个答案:

答案 0 :(得分:2)

这意味着要做这样的事情:

return grid?.Whatever;

如果grid为null,则?.返回null,或者如果它不为null,则引用Whatever。

如果您正在编写其他人必须维护的代码,我会忽略该建议。只是我的意见,但它使代码太容易被误读。