开发者

Difference between tp(,) and tpo(1)()

开发者 https://www.devze.com 2023-01-03 11:02 出处:网络
I have this code, first I thougt it should be the same but i cant acces the info in the same way .. why is this???

I have this code, first I thougt it should be the same but i cant acces the info in the same way .. why is this???

    Dim tp(,) As Integer = {{1, 3, 5, 9, 7}, {34, 3, 4, 5, 6}}
    Dim tp开发者_Go百科o(1)() As Integer
    tpo(0) = New Integer() {1, 3, 5, 9, 7}
    tpo(1) = New Integer() {34, 3, 4, 5, 6}

   For Each s As Integer In tp

        Console.WriteLine(s & ",")

    Next

    For Each di() As Integer In tpo

        For Each di2 As Integer In di

            Console.WriteLine(di2 & ",")
        Next

    Next

The first one I use only one for each and the other one I use two .. why is this different? are noy they 2 dimensional arrays ???


Your first array declared as

Dim tp(,) As Integer = {{1, 3, 5, 9, 7}, {34, 3, 4, 5, 6}}

declares a 2 dimensional rectangular array with the size of 5X5

Whereas

Dim tpo(1)() As Integer

declares a one dimensional array of integer arrays. This is called a jagged array. Each element in a jagged array can have a different length.

0

精彩评论

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