Solved

unassigned error

Posted on 2006-07-10
4
359 Views
Last Modified: 2012-05-05
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
Comment
Question by:Isaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 100 total points
ID: 17076634
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
 
LVL 5

Author Comment

by:Isaac
ID: 17076769
how can I convert this from vbscript to c#:
Just want to find out how many items in the array.

ubound(newArry,2)
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17076807

        string[,] myArr = new string[2, 10];
        int uBound = myArr.GetUpperBound(1);
0
 
LVL 5

Author Comment

by:Isaac
ID: 17076883
the getupperbound(1) did not work so I used .Length

Thanks anyway.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question