I've wrote a generic function to add an item to an Array 2D
This is what I have:
Private Sub Add_Item_Array_2D(ByRef Array_2D As String(,), _
ByVal Items As String())
Dim tmp_array(Array_2D.GetUpperBound(0) + 1, Array_2D.GetUpperBound(1)) As String
For x As Integer = 0 To Array_2D.GetUpperBound(0)
tmp_array(x, 0) = Array_2D(x, 0)
tmp_array(x, 1) = Array_2D(x, 1)
Next
For x As Integer = 0 To Items.Count - 1
tmp_array(tmp_array.GetUpperBound(0), x) = Items(x)
Next
Array_2D = tmp_array
End Sub
The code works, but I want to know if can be improved using Array.Resize method of LINQ extensions.
This is an usage example:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.shown
' Create Array 2D (2,2)
Dim MyArray As String(,) = _
{{"Item 0,0", "Item 0,1"}, {"Item 1,0", "Item 1,1"}, {"Item 2,0", "Item 2,1"}}
' Add Item
Add_Item_Array_2D(MyArray, {"Item 3,0", "Item 3,1"})
' Loop over the Array 2D
For x As Integer = 0 To MyArray.GetUpperBound(0)
MsgBox(String.Format("Array 2D {1},0: {2}{0}Array 2D {1},1: {3}", Environment.NewLine, _
x, MyArray(x, 0), MyArray(x, 1)))
Next
End Sub