Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Basic Array Push

Tags:

vb.net

I am currently iterating through a loop and redimensionalising my array every time I need to add a value (as you can imagine this takes some time for a redim every loop) is there a way I can implement a push similar to ruby or java? This would need to save the processing time needed to redimensionalise the array every time I need to add a value to it.

Cheers Martin

like image 779
marscom Avatar asked Dec 02 '22 23:12

marscom


2 Answers

You'd be better off using a List (Of Type). Then you can just call the Add method.

For example:

Dim foo As New List(Of String)
foo.Add("Bar")
like image 71
Andrew Cooper Avatar answered Dec 18 '22 23:12

Andrew Cooper


You can concat the array, with a array containing only the new item, or multiple.

Array.Concat({Item}).ToArray
like image 22
TheRealSuicune Avatar answered Dec 18 '22 21:12

TheRealSuicune