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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Readonly array elements 6
image array 1
dynamic length arrays 10
Declaring an array of List Generic Class elements 6
Declaring Data Buffer 1
Remove the element from array 4
Pointers to arrays 5
Large arrays in c# 9

Back
Top