unassigned error

What am I doing wrong? I get the following error:
Use of unassigned local variable 'newArry'

            string noZero = "1,3,5,6,7,9,10,14,16,17";
            string[] leadingZeros = noZero.Split(',');
            string[] newArry;

            int i = 0;
            foreach (string y in leadingZeros)
                if (y == "1" || y == "2" || y == "3" || y == "4" || y == "5" || y == "6" || y == "7" || y == "8" || y == "9")
                    newArry[i] = "0" + y;      <----- Use of unassigned local variable 'newArry'
                    newArry[i] = y;
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
You have only declared newArry as an array, you haven't actually created an array.

You either need to size the array initially, or use a more flexible container (perhaps an ArrayList).

    string[] newArry = new string[15];          // Size will be dependent on how many items it needs to hold
IsaacSharePoint Client Side DeveloperAuthor Commented:
how can I convert this from vbscript to c#:
Just want to find out how many items in the array.

Carl TawnSystems and Integration DeveloperCommented:

        string[,] myArr = new string[2, 10];
        int uBound = myArr.GetUpperBound(1);
IsaacSharePoint Client Side DeveloperAuthor Commented:
the getupperbound(1) did not work so I used .Length

Thanks anyway.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.