gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:48:20 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com