两个数组的笛卡尔连接

发布于 2024-12-05 14:30:26 字数 328 浏览 0 评论 0原文

我正在尝试使用 for next 循环来迭代数组并组合其字符串 我只能得到第一个数组。不知道如何编写代码以与第二个数组结合并使用 VB.NET 创建第三个数组。你能帮忙吗?

例如:

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

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

结果数组(81) = {A1, A2 ...A9, B1, B2...B9, ...I9}

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. Don'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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七月上 2024-12-12 14:30:26

在 C# 中,它是:

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

在 VB 中,结果放入数组变量中:

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

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()
往日情怀 2024-12-12 14:30:26

使用下面的逻辑(在 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);

希望这有帮助:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文