对象数组赋值总是报错
主程序是:Car[] car = new Car[3];
try
{
car[0].Name = "奔驰车";
car[0].Color = "红";
car[0].ProductPlace = "德国";
car[1].Name = "宝马车";
car[1].Color = "银灰";
car[1].ProductPlace = "德国";
car[2].Name = "宝马车";
car[2].Color = "银灰";
car[2].ProductPlace = "德国";
for (int i = 0; i < 3; i++)
{
Console.Write("我是一辆" + car[i].Name + ","
+ car[i].Color + "颜色,产地是" + car[i].ProductPlace);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
类是:
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string color;
public string Color
{
get { return color; }
set { color = value; }
}
private string productPlace;
public string ProductPlace
{
get { return productPlace; }
set { productPlace = value; }
}
private int speed;
出现:末将对象实例引用设置到对象的实例