Solved

unassigned error

Posted on 2006-07-10
4
352 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now