【问题标题】:displaying a 2d array as rows and columns in visual basic console在 Visual Basic 控制台中将二维数组显示为行和列
【发布时间】:2014-11-10 19:40:50
【问题描述】:

我正在尝试将下面的二维数组显示为行和列。

Module Module1

    Sub Main()

        'declaring and initializing a 2d array 
        Dim a1(,) As Integer = {{2, 3}, {5, 3}}

        For Each ele As Integer In a1

            Console.WriteLine(ele)


        Next

    End Sub

End Module

我需要像这样的输出:

2 5
3 3

我需要你们的帮助。请

【问题讨论】:

标签: arrays vb.net


【解决方案1】:

只需分别循环遍历每个维度:

For I as Integer = 0 to a1.GetUpperBound(0)
   For J as Integer = 0 to a1.GetUpperBound(1)
      Console.Write("{0} ", a1(j,i))
   Next
   console.WriteLine()
Next

演示:https://dotnetfiddle.net/8K7fkp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-24
    • 1970-01-01
    • 2020-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    相关资源
    最近更新 更多