I have the following code which transforms a List of myCar
objects to an Array of Car objects from a third-party web service so I can then pass the cars to the 3rd party web service:
var cars = new Car[myCars.Count];
var count = 0;
foreach (var myCar in myCars)
{
cars[count] = new Car
{
Id = myCar.Id,
Manufacturer = myCar.Manufacturer,
Model = myCar.Model
};
count++;
}
return cars;
Note as my myCar object has a number of other features other than the three the 3rd Party web service has I cant do something simple such as:
MyClass[] myArray = list.ToArray();
The code is working as expected but I am wondering is there something in Linq such as a Select expression which would make this better and take less code?