数组属性返回其他2个数组的计算结果 [英] Array property returns calculation of 2 other arrays

查看:31
本文介绍了数组属性返回其他2个数组的计算结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能具有一个数组属性,该属性在相同的索引处返回其他2个数组的计算结果?

Is it possible to have an array property that returns a calculation of 2 other arrays at the same index?

public ushort[] LowLimit{ get; set; }

public ushort[] Range{ get; set; }

public ushort[] HiLimit {
    get {
     return LowLimit + Range;
    }
}

因此,如果我调用 HiLimit [0] ,它将返回 LowLimit [0] + Range [0] .这是行不通的,但是必须有一种方法.

So if I called HiLimit[0] it would return LowLimit[0] + Range[0]. This is not working but there must be a way.

推荐答案

您可以使用LINQ

You can use 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();

这篇关于数组属性返回其他2个数组的计算结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆