Connecting Tech Pros Worldwide Forums | Help | Site Map

How we can declare dynamic array in vb.net

Himmat Solanki via .NET 247
Guest
 
Posts: n/a
#1: Nov 16 '05
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.

--------------------------------
From: Himmat Solanki

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>p3+b0EIBy0WXeQlqHuKhDA==</Id>

Larry Brasfield
Guest
 
Posts: n/a
#2: Nov 16 '05

re: How we can declare dynamic array in vb.net


"Himmat Solanki via .NET 247" <anonymous@dotnet247.com> wrote in
message news:ua0NAg0IFHA.608@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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.[/color]

Look at ArrayList. Yes. Yes.

And why do you post a vb.net question to a C# group?

--
--Larry Brasfield
email: donotspam_larry_brasfield@hotmail.com
Above views may belong only to me.


Fade BS via DotNetMonster.com
Guest
 
Posts: n/a
#3: Nov 16 '05

re: How we can declare dynamic array in vb.net


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

--
Message posted via http://www.dotnetmonster.com
Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#4: Nov 16 '05

re: How we can declare dynamic array in vb.net


Fade BS via DotNetMonster.com <forum@DotNetMonster.com> wrote:[color=blue]
> 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[/color]

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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Closed Thread


Similar C# / C Sharp bytes