Brett <no@spam.com> wrote:
I need an array but don't know how many items will go into it upon
declaration.
int ArrayIndex = 0;
string[] linkArray = new string[]{};
for (int i = 0; i < Links.Count; i++)
{
linkArray[ArrayIndex] = u.AbsoluteUri;
ArrayIndex++;
}
The first time through the loop, I get an out of bounds error. How exactly
does the array need to work in this case?
In this case, it's easy - you *do* know the number of links:
string[] linkArray = new string[Links.Count];
(You don't need the ArrayIndex variable either; just use i.)
If you genuinely don't know ahead of time how many items you need, use
an ArrayList and if you need to, call ToArray on the ArrayList.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too