Michael Cort

Michael Cort

  • NA
  • 6
  • 3.8k

Passing uninitialized array as argument

Mar 21 2012 2:26 PM
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.


Answers (3)