如何合并具有相同索引的两个数组,我列出了清单?

问题描述 投票:0回答:1

输入(伪代码):

var array1=[1,2,3,4];
var array2=[5,6,7,8];

结果(伪代码):

var output={[1,5],[2,6],[3,7],[4,8]};
c# asp.net asp.net-core asp.net-mvc-4 core
1个回答
0
投票

您可以使用LINQ的Zip方法:

var output = array1.Zip(array2, (a, b) => new [] { a, b });

如果需要它作为List<int>int[],则可以分别用.ToList().ToArray()来实现。

Try it online

© www.soinside.com 2019 - 2024. All rights reserved.