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,914 questions

51,847 answers

573 users

How to fill multiple columns of specific row of 2D Array in VB.NET

1 Answer

0 votes
Imports System

Module ArrayExtensions
    <System.Runtime.CompilerServices.Extension()>
	Public Sub FillValues(Of T)(arrayToFill As T(,), row As Int32, ParamArray items() As Array)
        For Each arr As Array In items
            Dim col As Int32 = CInt(arr.GetValue(0))
            Dim val As T = CType(arr.GetValue(1), T)
		
            arrayToFill(row, col) = val
        Next
    End Sub
End Module

Public Class Program
    Public Shared Sub PrintArray(ByVal array As Double(,))
        For i As Integer = 0 To array.GetUpperBound(0)
            For j As Integer = 0 To array.GetUpperBound(1)
                Console.Write(array(i, j) & " ")
            Next
            Console.WriteLine()
        Next
    End Sub

    Public Shared Sub Main()
       	Dim arr(12, 8) As Double

		' Fill row 3 - coloumns 2, 5, 6
		arr.FillValues(3, {2, 0.5}, {5, 9.13}, {6, 0.001})
		
		' Fill row 5 - coloumns 1, 3, 5, 7
		arr.FillValues(5, {1, 0.45}, {3, 8.76}, {5, 0.005}, {7, 96.563})

        PrintArray(arr)
    End Sub
End Class




' run:
'
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0.5 0 0 9.13 0.001 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0.45 0 8.76 0 0.005 0 96.563 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0 
' 0 0 0 0 0 0 0 0 0
'

 



answered Mar 14, 2023 by avibootz
...