I have a class:
class Cars
{
String Part;
int NrOfParts;
}
and a List<Cars>.
I would like to get the sum of NrOfParts for a specific Part using lambda expressions.
I would like something like this:
double sum = sil.Sum(item => item.NrOfParts WHERE item.Part == SomePart);
where sil is my list and SomePart is specific part I’m looking for.
The problem is that I don’t know how to add a where condition to restrict the search for a specific case.
You need to put the where clause first (using the where method), and then you sum over the filtered list.