Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

unassigned error

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

Console.WriteLine("----------------------------------------------------------");
            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'
                }
                else
                {
                    newArry[i] = y;
                }
                i++;
            }
0
Isaac
Asked:
Isaac
  • 2
  • 2
1 Solution
 
Carl TawnSystems 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
0
 
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.

ubound(newArry,2)
0
 
Carl TawnSystems and Integration DeveloperCommented:

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

Thanks anyway.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now