Clearing two-dimensional array
I am using a two-dimensional array of 10 elements, but my code is extremely slow.
Dim myArray As String(,)
For i=0 to 100
'Clear Array. (This line is really slow)
myArray = New String(,) {{"", ""}, {"", ""}, {"", ""}, _
{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}}
'Populate array
fillArray(myArray)
'Do stuff with array
useArray(myArray)
Next i
I 开发者_StackOverflow社区create a new empty array with every iteration of the for loop. Is there a way I can use the same array but just clear it instead?
It's unclear what you're using your array for, but you might want to look into using a collection instead.
As far as clearing the array is concerned, look into using Array.Clear.
Doesn't vb.net have a way to quickly create 2 dimensional arrays? It was something like:
Dim rectArray(10, 10) As String
Then you can populate as usual:
Dim rectArray(,) As String = {{'', '', '' ....etc
some reading that might help - link
精彩评论