By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,668 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,668 IT Pros & Developers. It's quick & easy.

How we can declare dynamic array in vb.net

P: n/a
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>
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Himmat Solanki via .NET 247" <an*******@dotnet247.com> wrote in
message news:ua*************@TK2MSFTNGP10.phx.gbl...
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?

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Nov 16 '05 #2

P: n/a
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
Nov 16 '05 #3

P: n/a
Fade BS via DotNetMonster.com <fo***@DotNetMonster.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.