making a local variable available

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am working on code that I have posted several questions on, they have been
helpful, but as I am new to programming, I have come across something else I
am not sure how to fix. This is a build error referring to an unassigned
local variable. The problem is this variable was defined in a local
procedure and is therefore not available when I need to use it. I have
posted a bit of the code I am working on, the bit with the problems. How can
I go about reworking this code to be able to use the results of splitting the
arraylist and using the resulting array 'aFields'? Any help is very much
appreciated.

foreach (string aOutput in aColumn)
{
aFields = aOutput.Split(new char[] {' '});
}
//Define maxRow to equal the upper bound of the aFields array
maxRow = aFields.GetUpperBound(0);
//For each i less than or equal to maxRow
for (int i=0; i <= maxRow;i++)
{
//Creates new double array
AFields = new double[maxRow +1];
 
Hi,

Basically you have two options:
1- Make aFields a member variable, declaring it outside any method and
inside the class
2- You may create a method that return it , in this form it can be used in
the calling method.

Cheers,
 
How would I go about creating a method that returns it?

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Basically you have two options:
1- Make aFields a member variable, declaring it outside any method and
inside the class
2- You may create a method that return it , in this form it can be used in
the calling method.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Christine said:
I am working on code that I have posted several questions on, they have been
helpful, but as I am new to programming, I have come across something else I
am not sure how to fix. This is a build error referring to an unassigned
local variable. The problem is this variable was defined in a local
procedure and is therefore not available when I need to use it. I have
posted a bit of the code I am working on, the bit with the problems. How can
I go about reworking this code to be able to use the results of splitting the
arraylist and using the resulting array 'aFields'? Any help is very much
appreciated.

foreach (string aOutput in aColumn)
{
aFields = aOutput.Split(new char[] {' '});
}
//Define maxRow to equal the upper bound of the aFields array
maxRow = aFields.GetUpperBound(0);
//For each i less than or equal to maxRow
for (int i=0; i <= maxRow;i++)
{
//Creates new double array
AFields = new double[maxRow +1];
 
Given that aFields has become a member variable it goes something like this:

class Joepie
{
private ArrayList aFields;

public ArrayList MyFields
{
get { return aFields; }
}

}
 
Back
Top