How we can declare dynamic array in vb.net

  • Thread starter Thread starter Himmat Solanki via .NET 247
  • Start date Start date
H

Himmat Solanki via .NET 247

How can we declare an array that have not afix length? and can it possible to inserts new itmes to it? as much as we want to enter.
 
Himmat Solanki via .NET 247 said:
How can we declare an array that have not afix length? and can it possible
to inserts new itmes to it? as much as we want to enter.

Look at ArrayList. Yes. Yes.

And why do you post a vb.net question to a C# group?
 
you declare the array as so:
dim Numbers as int32()

and then you can dnamically change size like so:
redim Numbers(100) ' <producing 101 items as indexes range from 0 to 100

Note: if you want to array to keep the values when you resize it,use:
redim preserve ( ? )

Note: you have to use 'Redim' at least once before accessing the array to
initiate it's size! otherwise an exception is thrown

that's it
 
Fade BS via DotNetMonster.com said:
you declare the array as so:
dim Numbers as int32()

and then you can dnamically change size like so:
redim Numbers(100) ' <producing 101 items as indexes range from 0 to 100

Note: if you want to array to keep the values when you resize it,use:
redim preserve ( ? )

Note: you have to use 'Redim' at least once before accessing the array to
initiate it's size! otherwise an exception is thrown

You can't do that in C#, however, and it's not *actually* changing the
size of the array - it's creating a new arrray and copying the old
data, which is inefficient if you do it often.
 
Back
Top