如何从其他两个数组创建数组?

时间:2014-09-23 08:50:16

标签: arrays vb.net

我有两个大小相同的数组。

Dim arr1() As String = {"Hello", "world", "I'm", "some", "text"}
Dim arr2() As String = {"Hello2", "world2", "I'm2", "some2", "text2"}

我需要从这两个数组中创建另一个*一个数组。

编辑: 这样的事情。

Dim arr3(0) As String = {"Hello", "Hello2"}
Dim arr3(1) As String = {"world", "world2"}
Dim arr3(2) As String = {"I'm", "I'm2"}
Dim arr3(3) As String = {"some", "some2"}
Dim arr3(4) As String = {"text", "text2"}

2 个答案:

答案 0 :(得分:0)

您也可以使用 Enumerable.Zip

Dim res = arr1.Zip(arr2, Function(a,b) {a,b})

答案 1 :(得分:0)

您正在寻找Zip

  

Enumerable.Zip(Of TFirst,TSecond,TResult)方法

     

将指定的函数应用于两个序列的相应元素,生成一系列结果。

示例:

Dim arr1() As String = {"Hello", "world", "I'm", "some", "text"}
Dim arr2() As String = {"Hello2", "world2", "I'm2", "some2", "text2"}

Dim arr3 = arr1.Zip(arr2, Function(a, b) {a, b}).ToArray()