Using LINQ to convert List<U> to List<T>
var iweilCopy = sil.Select(item => new InvoiceWithEntryInfo()
{
IdWEI = item.Id,
NameWEI = item.Name,
....
}).ToList();
var iweil = sil.Select(item=> new InvoiceWithEntryInfo {
IdIWEI = item.ID,
AmountIWEI = item.Amount,
DateIWEI = item.Date}).ToList();
You need a function to convert a T
instance to a U
instance:
ResultType ConvertMethod(StartType input)
and you need to write this. Then
outputList = inputList.Select(ConvertMethod).ToList();
will apply it to the whole input collection. The conversion function can be a lambda written inline but doesn't need to be (if the function has the right signature, like ConvertMethod
then the compiler will convert it correctly to pass to Select
).