我想定义一个类数组,差不多类似于C语言里的结构体数组一样。可是当我写如下代码测试的时候,却不能运行,请高手不仅赐教。谢谢!class TestClass
{
public String A = null;
public String B = null;
} class Program
{
static void Main(string[] args)
{
int n = 3;
TestClass[] tc = new TestClass[n];
tc[0].A = "A0";
tc[0].B = "B0";
tc[1].A = "A1";
tc[1].B = "B1";
tc[2].A = "A2";
tc[2].B = "B2";
Console.WriteLine("{0},{1}", tc[0].A, tc[0].B);
Console.WriteLine("{0},{1}", tc[1].A, tc[1].B);
Console.WriteLine("{0},{1}", tc[2].A, tc[2].B);
Console.Read();
}
}
{
public String A = null;
public String B = null;
} class Program
{
static void Main(string[] args)
{
int n = 3;
TestClass[] tc = new TestClass[n];
tc[0].A = "A0";
tc[0].B = "B0";
tc[1].A = "A1";
tc[1].B = "B1";
tc[2].A = "A2";
tc[2].B = "B2";
Console.WriteLine("{0},{1}", tc[0].A, tc[0].B);
Console.WriteLine("{0},{1}", tc[1].A, tc[1].B);
Console.WriteLine("{0},{1}", tc[2].A, tc[2].B);
Console.Read();
}
}
tc[0].A = "A0";
tc[0].B = "B0";
明白了 我是没有对数组里的对象进行实例化