我有这个代码块
double[] tabHeight = { 16, 10, 15, 20 };
double[] tabMidSectionWA = { 6, 2, 5, 6 };
double[] tabCurveWA = {
(tabHeight[0] - tabMidSectionWA[0]) / 2 ,
(tabHeight[1] - tabMidSectionWA[1]) / 2,
(tabHeight[2] - tabMidSectionWA[2]) / 2 ,
(tabHeight[3] - tabMidSectionWA[3]) / 2
};
Run Code Online (Sandbox Code Playgroud)
是否有(tabheight - tabMid) / 2使用 for 循环或 foreach的公式添加这些值的更简单方法?
您可以将 Linq 与 Enumerable.Zip
var result = tabHeight.Zip(tabMidSectionWA,(x,y)=>(x-y)/2).ToArray();
Run Code Online (Sandbox Code Playgroud)
Enumerable.Zip 将指定的函数应用于两个序列的相应元素,产生一系列结果。
输出
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |