Using .NET 3.5, but the Select call gives the error. Shouldn’t the compiler be clever enough to infer this? If not, why not?
public IEnumerable<Customer> TableToCustomers(Table table)
{
return table.Rows.Select(RowToCustomer);
}
private Customer RowToCustomer(TableRow row)
{
return new Customer { ... };
}
The
Rowsproperty is defined asTableRowCollection Rows {get;}It is not
IEnumerable<TableRow>, so it is justIEnumerable, therefore it cannot infer the type as beingTableRow.You can do this instead: