Imports System
Public Class PrintMatrixRowsAndColumns_VB
Public Shared Sub printMatrixRows(ByVal matrix As Integer(,))
For i As Integer = 0 To matrix.GetLength(0) - 1
Console.Write("row: {0:D}: ", i)
For j As Integer = 0 To matrix.GetLength(1) - 1
Console.Write("{0,4:D} ", matrix(i, j))
Next
Console.WriteLine()
Next
End Sub
Public Shared Sub printMatrixColumns(ByVal matrix As Integer(,))
For j As Integer = 0 To matrix.GetLength(1) - 1
Console.Write("column {0:D}: ", j)
For i As Integer = 0 To matrix.GetLength(0) - 1
Console.Write("{0,4:D} ", matrix(i, j))
Next
Console.WriteLine()
Next
End Sub
Public Shared Sub Main(ByVal args As String())
Dim matrix As Integer(,) = {
{4, 7, 9, 18, 29, 0},
{1, 9, 18, 99, 4, 3},
{9, 17, 89, 2, 7, 5},
{19, 49, 6, 1, 9, 8},
{29, 4, 7, 9, 18, 6}}
printMatrixRows(matrix)
Console.WriteLine()
printMatrixColumns(matrix)
End Sub
End Class
' run:
'
' row: 0: 4 7 9 18 29 0
' row: 1: 1 9 18 99 4 3
' row: 2: 9 17 89 2 7 5
' row: 3: 19 49 6 1 9 8
' row: 4: 29 4 7 9 18 6
'
' column 0: 4 1 9 19 29
' column 1: 7 9 17 49 4
' column 2: 9 18 89 6 7
' column 3: 18 99 2 1 9
' column 4: 29 4 7 9 18
' column 5: 0 3 5 8 6
'
'