开发者

adding blank elements to array

I have an array x in size of objects (between 1 and 100) and I want to increase the size to 101 ... I've resized the array and that adds the objects but unfortunatly (not suprising) the added items have not been initialised, do I've reverted to using a do while loop and adding the elements indiviually, but looking at the code around it where addrange is used extensivily, I was just wondering if that was a neat vb.net way of doing the same thing开发者_如何学C

Bit of a learning question, just looking for neat ways to do the same thing

Thanks in advance


Yes you need to loop and add new objects into newly added indexes.


Try not using an array but a List instead. They're much easier to use and give more control.

Dim myList As List(Of Whatever)  
myList.Add(New Whatever)


Are you looking for this....

ReDim PRESERVE thatArray(to_the_new_size)

The preserve should, uhm, preserve the original values in their original places.


I am (then) not sure what your looking to accomplish... using ReDim Preserve (older) or the .reSize (newer) will certainly add to the "end" of the array and those elements MUST BE null since you cannot pass new elements into the constructor.

But is that what your looking for ? A way to pass the new values into the constructor of the new elements so it returns with the old-er values as will as the new ones?

Even if you overload the constructor, you'll have to LOOP the new values in. (As far as I can see.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜