How to find the length (rows, cols) of 2D array in VB.NET

4 Answers

0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim array2d(2, 3) As Integer
 
        Console.WriteLine("rows: {0}", array2d.GetUpperBound(0))
        Console.WriteLine("columns: {0}", array2d.GetUpperBound(1))
	End Sub
End Module




' run:
' 
' rows: 2
' columns: 3
'
 

 



answered Mar 1, 2016 by avibootz
edited Aug 10, 2023 by avibootz
0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim array2d(,) As Integer = New Integer(,) {{1, 8, 5}, 
													{6, 7, 1}}
 		
		Dim rows As Integer = array2d.GetUpperBound(0) + 1
		Dim cols As Integer = array2d.GetUpperBound(1) + 1
		
        Console.WriteLine("rows: {0}", rows)
        Console.WriteLine("columns: {0}", cols)
	End Sub
End Module




' run:
' 
' rows: 2
' columns: 3
'
 

 



answered Mar 1, 2016 by avibootz
edited Aug 10, 2023 by avibootz
0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim array2d(,) As Integer = New Integer(,) {{1, 8, 5}, 
													{6, 7, 1}}
 		
		Dim rows As Integer = array2d.GetLength(0)
		Dim cols As Integer = array2d.GetLength(1)
		
        Console.WriteLine("rows: {0}", rows)
        Console.WriteLine("columns: {0}", cols)
	End Sub
End Module




' run:
' 
' rows: 2
' columns: 3
'
 

 



answered Apr 11, 2016 by avibootz
edited Aug 10, 2023 by avibootz
0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim array2d(2, 3) As Integer
         
        Dim rows As Integer = array2d.GetLength(0) - 1
        Dim cols As Integer = array2d.GetLength(1) - 1
         
        Console.WriteLine("rows: {0}", rows)
        Console.WriteLine("columns: {0}", cols)
	End Sub
End Module




' run:
' 
' rows: 2
' columns: 3
'
 

 



answered Aug 10, 2023 by avibootz
edited Aug 10, 2023 by avibootz

Related questions

1 answer 245 views
1 answer 180 views
1 answer 176 views
4 answers 343 views
2 answers 220 views
1 answer 131 views
131 views asked Apr 18, 2018 by avibootz
1 answer 182 views
...