2014-04-09 2 views
0
에서 계산하는

의 나는 다음과 같은 상황이 있다고 가정하자Linq는 내면의 목록

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? 
    } 
} 

그것이 가능 LINQ를 통해이 수를 얻을 수 있습니까?

감사합니다.

답변

6

를 사용하여 간단한 Enumerable.Sum (중고 장비 구매와 listB 모두 그렇지 않으면 널 체크를 추가 할 필요가, null이 아닌 가정) : :-) ... 나는 "합계"에 대해 잊어 버린 수 있는지,

int total = listABC.Sum(abc => abc.listA.Count + abc.listB.Count); 
+1

남자 감사! – AndreMiranda