主题:一个简单的问题(关于对象的作用域)
using System;
namespace ConsoleApplication1
{
class Text
{
public class A
{
public string str;
public A()
{
str = null;
}
}
public static void Input()
{
A[] a = new A[2];
for (int i = 0; i < 2; i++)
{
a[i] = new A();
a[i].str = Console.ReadLine();
}
}
public static void Output()
{
A[] a = new A[2];
for (int i = 0; i < 2; i++)
{
a[i] = new A();
Console.WriteLine("{0}", a[i].str);
}
}
public static void Main()
{
Input();
Output();
}
}
}
怎么样扩大"a[i].str"的作用域,使得Output函数不用再定义类a而能用Output函数来输出从Input函数输入的值
namespace ConsoleApplication1
{
class Text
{
public class A
{
public string str;
public A()
{
str = null;
}
}
public static void Input()
{
A[] a = new A[2];
for (int i = 0; i < 2; i++)
{
a[i] = new A();
a[i].str = Console.ReadLine();
}
}
public static void Output()
{
A[] a = new A[2];
for (int i = 0; i < 2; i++)
{
a[i] = new A();
Console.WriteLine("{0}", a[i].str);
}
}
public static void Main()
{
Input();
Output();
}
}
}
怎么样扩大"a[i].str"的作用域,使得Output函数不用再定义类a而能用Output函数来输出从Input函数输入的值