Object initializers not working in List<T>.
- by Jebli
List<Car> oUpdateCar = new List<Car>();
oUpdateCar.Add(new Car());
oUpdateCar[0].name = "Color";
oUpdateCar[0].value = "red";
oUpdateCar.Add(new Car());
oUpdateCar[1].name = "Speed";
oUpdateCar[1].value = "200";
The above code is working but i want to initialize it when i create the list as below,
List<Car> oUpdateCar = new List<Car>
{
new Car{
name = "Color";
value = "red";}
new Car{
name = "Speed";
value = "200";}
}
The above code is not working. What am i missing. I am using c# .NET 2.0. Please help.