是否可以有一个数组属性返回同一索引处的 2 个其他数组的计算结果?
public ushort[] LowLimit{ get; set; }
public ushort[] Range{ get; set; }
public ushort[] HiLimit {
get {
return LowLimit + Range;
}
}
因此,如果我调用 HiLimit[0]
,它将返回 LowLimit[0] + Range[0]
。这行不通,但一定有办法。
最佳答案
您可以使用 LINQ Zip运算符(operator):
Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
public ushort[] HiLimit => LowLimit.Zip(Range, (l,r) => (ushort)(l + r)).ToArray();
关于c# - Array 属性返回 2 个其他数组的计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42006445/