【发布时间】:2019-01-02 21:27:25
【问题描述】:
我想测试Output.ScriptPubKey.Addresses 数组是否为空,然后将其分配给参数列表。如果为null,那么我想将参数值设置为0,否则使用数组中的项目数。
我在下面写的感觉很笨拙和冗长,有没有更优雅的方式?
int addressCount;
if (Output.ScriptPubKey.Addresses == null) { addressCount = 0; } else {
addressCount = Output.ScriptPubKey.Addresses.Length;
}
var op = new DynamicParameters();
op.Add("@AddressCount", addressCount);
以前的代码是:
op.Add("@AddressCount", Output.ScriptPubKey.Addresses.Length);
但有时Addresses 数组为空。
【问题讨论】:
-
op.Add("@AddressCount", Output.ScriptPubKey.Addresses?.Length ?? 0);