c# - Array 属性返回 2 个其他数组的计算

标签 c# arrays

是否可以有一个数组属性返回同一索引处的 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/

相关文章:

javascript:是否可以自动将对象推送到空数组(创建时)?

c# - 无法让级联删除在 EF 中工作

c# - 查询字符串检查

c# - 明确的 SSL/TLS 版本选择

c# - 为什么我多了一个角色?

c# - asp.net core获取当前用户的方法

java - Groovy-List、ArrayList 和 Object Array 的区别

javascript - 在循环内构建 2 级 JavaScript 数组

ios - 如何从 NSDictionary 的 NSArray 的 NSArray 迭代和检索值

arrays - 如何删除作为较大元素子集的单元格元素? (Matlab)