I am trying to pass an array to a subroutine that will populate it. It doesn't like that the array is not initialized before passing it. I don't know how many elements the array will have as that is determined in the subroutine. How can I fix this?
Here is an example
private void x
{
......
string sTestFile = "this is a test";
string[] TestFileWords;
FixConcatString(sTestFile, TestFileWords);
}
private void FixConcatString(string splayfile, string[] sWordArray)
{
char[] charSeparators = new char[] { '-' };
splayfile = splayfile.ToLower();
splayfile = splayfile.Replace(@"\", " ");
sWordArray = splayfile.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
}
It gawks that I am passing TestFileWords to the subroutine without initializing it.
Loading

VulpesRank #55 · 29.2K reputationPosted Mar 21, 2012, 10:42 AM EDT
Michael Cort6 reputationPosted Mar 21, 2012, 10:49 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 21, 2012, 10:50 AM EDT
The same applies when you use 'ref' rather than 'out'.