Imports System
Public Class Program
Public Shared Sub Main(ByVal args As String())
Dim array As Integer(,) = {
{ 5, 8, 2 },
{ 4, 1, 7 },
{ 3, 9, 6 }
}
SortRows(array)
Print2DArray(array)
End Sub
Public Shared Sub SortRows(ByVal array As Integer(,))
Dim rows As Integer = array.GetLength(0)
Dim cols As Integer = array.GetLength(1)
For i As Integer = 0 To rows - 1
Dim row As Integer() = New Integer(cols - 1) {}
For j As Integer = 0 To cols - 1
row(j) = array(i, j)
Next
Array.Sort(row)
For j As Integer = 0 To rows - 1
array(i, j) = row(j)
Next
Next
End Sub
Public Shared Sub Print2DArray(ByVal array As Integer(,))
Dim rows As Integer = array.GetLength(0)
Dim cols As Integer = array.GetLength(1)
For i As Integer = 0 To rows - 1
For j As Integer = 0 To cols - 1
Console.Write(array(i, j) & " ")
Next
Console.WriteLine()
Next
End Sub
End Class
' run:
'
' 2 5 8
' 1 4 7
' 3 6 9
'