ReDim Statement

June 18, 2007 at 6:07 am (.NET, ASP.NET)

ReDim statement is used to resize an existing array.

Example :-

Dim names(2) as String = {“james”,”jack”,”rose”}

now if we need to add another name then we can resize the array using the ReDim statement.

ReDim names(3)

In the above example the old data in the array will be deleted when redimmed, We can use the Preserve keyword to retain the old data while ReDimming.

ReDim Preserve names(3)

What it actually does is that it copies the old data into the new array with the new size and then delete the old one thereforel it is better to avoid using ReDim statement. Instead you can use ArrayList if the exact size is not known.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: