Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to sort each row from a two-dimensional rectangular array in VB.NET

1 Answer

0 votes
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 
'

 



answered Mar 15, 2025 by avibootz
edited Mar 15, 2025 by avibootz
...