开发者

Cartesian join of two arrays

开发者 https://www.devze.com 2023-04-07 02:57 出处:网络
I am trying to use a for next loop to iterate through the arrays and combine its strings I can only get the first array. Do开发者_StackOverflow中文版n\'t know how to code to combine with the second on

I am trying to use a for next loop to iterate through the arrays and combine its strings I can only get the first array. Do开发者_StackOverflow中文版n't know how to code to combine with the second one and create the third array using VB.NET. could you help please?

ex:

arrLetters() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I"}

arrNumbers() As String = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}

resulting array(81) = {A1, A2 ...A9, B1, B2...B9, ...I9}


In C# it would be:

from letter in arrLetters
from number in arrNumbers
select letter + number

In VB, with the result going in to an array variable:

    Dim array = (From letter In arrLetters
                 From number In arrNumbers
                 Select letter + number).ToArray()


Use below logic (In C#)

    var arrLetters= new string[] {"A", "B", "C", "D", "E", "F", "G", "H", "I"};
    var arrNumbers = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    var array = arrLetters.Zip(arrNumbers, (letter, word) => letter + word);

Hope this helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号