Search code examples
c#linqconvertall

why does C# convertall require 2 parameters


I have an array of Car objects

I want to conver them to a list of Vehicle objects

I thought this would work

Vehicle[] vehicles = cars.ConvertAll(car=> ConvertToVehicle(car)).ToArray();

but its complaining that ConvertAll requires two parameters.

here is the error:

Error 2 Using the generic method 'System.Array.ConvertAll(TInput[], System.Converter)' requires '2' type arguments C:\svncheckout\latestTrunk\Utility\test.cs 229 33

am i using the wrong method here?


Solution

  • You're using ConvertAll on an Array of cars (Car[]) instead of a List of cars (List) which does indeed require two type parameters1. If cars is a list your code will work.