unassigned error

Posted on 2006-07-10
Last Modified: 2012-05-05
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;
Question by:Isaac
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
LVL 52

Accepted Solution

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

Author Comment

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

LVL 52

Expert Comment

by:Carl Tawn
ID: 17076807

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

Author Comment

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

Thanks anyway.

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 51
Where is this file? 3 33
need to convert function to c# 5 45
C# Linq Select From List 3 50
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…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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