How to extract a row from a rectangular array to a one-dimensional array in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Public Class Program
    Public Shared Sub Main()
        Dim rectangularArray As String(,) = New String(2, 2) {
        	{"a", "b", "c"},
        	{"d", "e", "f"},
        	{"g", "h", "i"}}
        
		Dim rowNum As Integer = 1
		
        Dim row As Object() = Enumerable.Range(0, rectangularArray.GetLength(1)).
		                      Select(Function(col) CObj(rectangularArray(rowNum, col))).
							  ToArray()
			
        Console.Write(String.Join(", ", row))
    End Sub
End Class


' run:
'
' d, e, f
'

 



answered Mar 13, 2025 by avibootz
...