Infinite Array in C#

by Damiaan Peeters 31. January 2008 08:11

In VB you can ReDim an array.

In C# there is nothing such as a Redim Preserve.  You can only copy everything into a new array like this
string [] names2 = new string[7];
Array.Copy(names, names2, names.Lenght);

When using .Net 2.0 or later, I would suggest using Generics.  You can use generics like this
for a list of strings:
List<string> names = new List<string>();
Or a list of objects:
List <myClass> myList = new List<myClass>();

If you want an infinit 'Array' of int's you can use:
List <int> myRow = new List<int>();
List <myRow> infinitArray = new List<myRow>();


Tags: ,


blog comments powered by Disqus

Certified Umbraco Master, Part of Umbraco Certified partner comm-it, .Net and Azure developer, seo lover. Magician in my spare time.

Month List