Dynamic Arrays in C#

Submitted By: Unknown
Rating: starstarstarhalf star (Rate It)
Share: Share By Email By Email

Visit


Description

This article shows how to create dynamic arrays in C# (.NET).

Comments (34)

Good One starstarstar   Posted by: Rami Reddy MVB on Tuesday, March 25, 2003

Good Article

Useful starstarstarstar   Posted by: Karen on Tuesday, January 06, 2004

Very useful article!

Only 1 remark. This:
string[] aFoo = new string[9];
assigns to array aFoo 9 elements, not 10.

Respect, yes!

very helpful and not coplex starstarstarstarstar   Posted on Saturday, April 17, 2004

I know its a simple topic but very helpful.

Eventually! starstarstarstar   Posted by: Gary Hall on Friday, August 13, 2004

I spent ages looking for C# dynamic arrays tutorials, this explanation came in very handy.

Ta.

very nice starstarstarstar   Posted on Monday, March 14, 2005

simple, effective, great..

Very good starstarstarstarstar   Posted on Tuesday, January 17, 2006

Very helpful - thanx

Just What Was Needed starstarstarstar   Posted by: Jim on Thursday, March 09, 2006

Bump. Very useful. Short and sweet.

Answered exactly what I was looking for! starstarstarstarstar   Posted on Wednesday, May 02, 2007

Very well written

excellent starstarstarstarstar   Posted on Friday, August 24, 2007

It's very useful

This is not what the title says   Posted on Thursday, August 30, 2007

it is supposed to be a tutorial teaching how to create dynamic arrays and not how to escape creating dynamic arrays and using Arraylist instead. I give u a 0

upperbound starstarstarstarstar   Posted by: jay on Wednesday, September 19, 2007

If you use an array, there is GetUpperBound method. Is there any property/method in arraylist?

Extremely Helpful and easy! starstarstarstarstar   Posted on Wednesday, November 14, 2007

Good Article!

C# Nuub starstarstarstarstar   Posted on Thursday, November 15, 2007

Thank you for explaining dynamic arrays in C#. I've been looking for a c++ vector replacement and I think I've found it in ArrayList!

Excellent Resource! starstarstarstarstar   Posted by: Andrew on Friday, February 29, 2008

Thanks a lot for this tutorial. It helped me a lot!

Very Good Article starstarstarstarstar   Posted by: Vanessa on Tuesday, March 25, 2008

This is a very good article and very easy of understand. I recommended.

Very useful article starstarstarstarstar   Posted on Friday, May 30, 2008

This article was exactly the information I was looking for, including the explanations and code samples. Excellent!

Good, but better to use List<T> now instead of ArrayList starstarstarstar   Posted by: Jink on Friday, August 15, 2008

Better performance, avoids boxing.

dyhy starstarstarstarstar   Posted by: htyh on Thursday, September 18, 2008

hhhh

Dynamic? star   Posted by: Drew Perrett on Monday, October 06, 2008

There is nothing dynamic about this array creation method, just hard coded rubbish.

Dynamic? 2 star   Posted by: Noel on Wednesday, January 07, 2009

Agreeing with Dynamic? 1

Dynamic? 2 star   Posted by: Noel on Wednesday, January 07, 2009

Agreeing with Dynamic? 1

Looks good! starstarstarstarstar   Posted by: Roger on Tuesday, February 10, 2009

What hard-coded about this? It does what it advertises - makes a dynamic list of things. Whether you call that an array, an arraylist, or your Grandma's shoes, the result is the same - a list of stuff with no defined start or end point. Well done!

nonsense star   Posted by: stefko on Thursday, March 05, 2009

It is not an array, it is a collection of objects.

thank you starstarstarstar   Posted by: meysam rahimi on Friday, March 06, 2009

thank you for your describtion. that was so fantastic.

dynamic string array starstarstarstarstar   Posted by: m behrens on Tuesday, June 23, 2009

its fine but
here is my version of pascal's setLength for C#.
It makes string arrays not only larger, but truncates them also.
Feel free to use it and be aware of the "ref" directive needed in your call.
private void setLength(ref string[] arr, int newLength)
{
if (arr == null) arr = new string[newLength]; else
{
string[] tempArr = new string[newLength];
for (int i = 0; i < newLength; i++)
if (i < arr.Length) tempArr[i] = arr[i];
else tempArr[i] = "";
arr = new string[newLength];
for (int i = 0; i < newLength; i++) arr[i] = tempArr[i];
}
}

This article perfect starstarstarstarstar   Posted by: Hasan on Sunday, July 19, 2009

Good job man. Thanks a lot

good one starstarstarstarstar   Posted by: umesh on Friday, January 15, 2010

This article perfect

thanks..very useful article starstarstarstarstar   Posted by: suresh on Friday, April 02, 2010

fail star   Posted by: fail on Friday, June 25, 2010

the goddamn link doesn't even work!

404 Error...Link is down star   Posted by: Eric Layne on Monday, July 19, 2010

404 Error...Link is down

Old link dead copy following link. I just googled starstarstarstar   Posted by: ramkumar on Tuesday, August 03, 2010

http://authors.aspalliance.com/remas/ASP.NET/VFAQNET/DynamicArrays/

this sucks star   Posted by: Programmer's hell on Monday, November 15, 2010

You used a link and now the link is down and all you have a a bunch of posts saying how good this is. If this is typical of programmers heaven then they should rename themselves programmes hell

dead link star   Posted by: Pierre on Thursday, February 24, 2011

I concur with the previous poster. Please post solutions in the forum, not links to solutions, unless it is within the same forum.

Dead Link star   Posted by: Matt on Sunday, February 10, 2013

Definately Programmers Hell.
I Declare Fudgemuffins.

Add Your Rating

(Not published)
star
starstar
starstarstar
starstarstarstar
starstarstarstarstar
 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.