Imports System
Module Module1
Sub Main()
Dim a(,) As Integer = New Integer(,) {{1, 8, 5}, {6, 7, 1}, {8, 7, 6}}
Dim b(,) As Integer = New Integer(,) {{4, 8, 1}, {6, 5, 3}, {4, 6, 5}}
Dim bound0 As Integer = a.GetUpperBound(0)
Dim bound1 As Integer = a.GetUpperBound(1)
Dim c(bound0, bound1) As Integer
Print(a)
Console.WriteLine()
Print(b)
Console.WriteLine()
'// c[0, 0] = (a[0, 0] * b[0, 0]) + (a[0, 1] * b[1, 0]) + (a[0, 2] * b[2, 0])
For i As Integer = 0 To a.GetUpperBound(0)
For j As Integer = 0 To a.GetUpperBound(1)
c(i, j) = Calc(a, b, i, j)
Next
Next
Print(c)
End Sub
Sub Print(arr2d(,) As Integer)
For i As Integer = 0 To arr2d.GetUpperBound(0)
For j As Integer = 0 To arr2d.GetUpperBound(1)
Console.Write("{0,4}", arr2d(i, j))
Next
Console.WriteLine()
Next
End Sub
Function Calc(a(,) As Integer, b(,) As Integer, i As Integer, j As Integer) As Integer
Dim sum As Integer = 0
For x As Integer = 0 To a.GetUpperBound(0)
sum = sum + a(i, x) * b(x, j)
Next
Return sum
End Function
End Module
' run:
'
' 1 8 5
' 6 7 1
' 8 7 6
' 4 8 1
' 6 5 3
' 4 6 5
' 72 78 50
' 70 89 32
' 98 135 59
'