Martin
For a start you've created an array with no space, although that may have
been your intention. In C# you set the initial size of the array by setting
how many elements you want and not the upper bound ordinal. To "expand" the
array you'll need to actually create a new instance of the array with more
elements and copy the contents across.
string[] myArray = new string[1];
myArray[0] = "x";
string[] tempArray = new string[2];
myArray.CopyTo( tempArray, 0 );
myArray = tempArray;
myArray[1] = "y";
Not my best code and not very efficient, but hopefully you get the idea.
Personally, if I don't know the size of an array I either use an ArrayList
..net 1.x or, in .Net 2 a generic like List<string>
List<stringmyLi st = new List<string>();
myList.Add( "x" );
myList.Add( "y" );
//if you want it as a string[] array...
string[] myArray = myList.ToArray( );
..Net provides a whole bunch of different types of collections for you to use
built for different tasks. See the System.Collecti ons namespace
documentation.
HTH
Glenn
"Visual Systems AB (Martin Arvidsson)" <ma************ **@vsab.netwrot e in
message news:eD******** ******@TK2MSFTN GP04.phx.gbl...
Hi!
Got a simple question. I am new to c# but this is not making me any sence.
If i declare: string[] myStringArray = new string[0];
How the heck could i fill it with more than one element?
Regards
Martin