Click to See Complete Forum and Search --> : [2.0] redim array in C#?
high6
May 1st, 2007, 02:03 PM
Well I got an array that I need to remove and add things constantly and the size is gonna vary so just giving it a bunch of slots wont work. is there a fast way to add to an array?
penagate
May 1st, 2007, 02:27 PM
Use a List<T>.
Fromethius
May 1st, 2007, 04:31 PM
or an ArrayList
But List<T> is cooler. Especially with classes :D
penagate
May 1st, 2007, 04:57 PM
You shouldn't use ArrayList in .NET 2.0, it's needlessly inefficient.
David Anton
May 1st, 2007, 05:15 PM
If you really need to use an array, then .NET 2 does have 'Resize' method on the Array class.
jmcilhinney
May 1st, 2007, 06:34 PM
As David says, the Array class now has a Resize method, which I'd choose to use in VB too. Having said that, you should only use an array and its Resize method if you will be resizing very infrequently. From this:I need to remove and add things constantlyyou should definitely use a List. Note that the List class is implemented using an internal array, but the class handles the resizing in as efficient a way as possible. To achieve the same result you'd have to needlessly write a fair bit of code.
RaviIntegra
May 3rd, 2007, 02:19 AM
you can resize your array by using the following code.
Array[] a;
a = new Array[100];
penagate
May 3rd, 2007, 02:23 AM
That will erase it all, though.
Also, that code is an array of arrays.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.