Dynamic arrays

Use this board to post your code snippets - tips and tricks
2 posts Page 1 of 1
Contributors
User avatar
Ffenixw0rks
VIP - Donator
VIP - Donator
Posts: 152
Joined: Sun Jun 19, 2011 2:51 pm

Dynamic arrays
Ffenixw0rks
So I've had problem with dynamic arrays, or rather with their length.
Here is what I've found:
Code: Select all
'Creating array
Dim SomeArray() As String
Next lets say we are parsing data and we need to set array length to parsed data length.
Code: Select all
Dim newArray As String() = Data.Split(vbCrLf)
Final part:
Code: Select all
ReDim SomeArray(newArray.Length)
But better would be do create array like
Code: Select all
Dim SomeArray(-1) As String
in case if you will clear array before using it.
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Dynamic arrays
mandai
Specifying the array length as -1 in VB.Net will make an empty array. I suppose if you want to re-use the variable it might be useful.
2 posts Page 1 of 1
Return to “Quick Snips”