您好,有没有办法制定如下所示的条件?如果field为null则为false else field.Property?
class Node
{
public bool IsFilled;
}
class Holder
{
Node nodeBuffer;
public bool IsFilled => this.nodeBuffer?.IsFilled ?? false;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么说if nodeBuffer is null then false else nodeBuffer.IsFilled呢?
是的,您可以使用与之一起使用的相等运算符Nullable<bool>
public bool IsFilled => this.nodeBuffer?.IsFilled == true;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |