Reputation: 6588
Let's suppose I have the following situation:
public class ABC
{
public List<A> listA { get; set; }
public List<B> listB { get; set; }
}
public class Test
{
public void LetsCount(List<ABC> listABC)
{
//int total = it's the total of all listA plus the total of all listB inside listABC... is it possible via linq?
}
}
Is it possible to get this count via linq?
Thanks!!
Upvotes: 0
Views: 162
Reputation: 236188
Use simple Enumerable.Sum
(assume both listA and listB are not null, otherwise you need to add null-check):
int total = listABC.Sum(abc => abc.listA.Count + abc.listB.Count);
Upvotes: 6