void Foo()
{
var xMaybeNull = GetX();
if (xMabyeNull == null) return; // Some way to get rid of this extra
// sentence without loosing the check
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
简单的方法是这样,但编译器需要一个表达式.
void Foo()
{
List<Disc[,]> xNeverNull = GetX() ?? return;
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
问题是,有没有办法写出someSortOfReturnExpression
(我猜不是)或另一种解决方案,可以在一条线上做我正在寻找的东西?
void Foo()
{
List<Disc[,]> xNeverNull = GetX() ?? someSortOfReturnExpression;
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
122 次 |
最近记录: |