Forum guidelines
AuthorQuestion
Limitless Array .. ?
Posted on: 16 Dec 2012
is there a limitless array in c# lang. ?
and if so ..
how to identify it ?

AuthorReply
Vulpes
  • 0
  • 0
accepted
Re: Limitless Array .. ?
Posted on: 17 Dec 2012   Accepted Answer
Well, in theory, an array in .NET can hold up to (approximately) 2 billion elements. However, in practice you'll probably have run out of memory well before then.

Once created an array always maintains its original size. So, if you create an array with a thousand elements, it will always have a thousand elements until it is disposed of.

You can resize an array (using Array.Resize) but all you're really doing is creating another array (of the required size) and copying the elements of the old one to it.

If you don't know in advance how many elements an array will need, then it's usually preferable to create an ArrayList or (better) a List<T>. These start with a (usually low) initial capacity which is doubled automatically as new elements are added. However, as these classes use an array for their internal storage, the doubling process can only go on ( memory permitting) as long as the limit of 2 billion elements is not exceeded.

So, the strict answer to your question is 'no' - there is no such thing as a limitless array in C#.

Employers - Post Free Jobs

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.