Count() 같은 대부분의 확장 메서드는 Where() 메서드를 사용하지 않고도 바로 매개변수로 람다 식을 전달하여 조건을 처리할 수 있습니다. 다음 내용을 입력한 후 실행해 보세요.
Where( ) 메서드를 사용하지 않고 조건 처리: CountFunc.cs
using System;
using System.Linq;
class CountFunc
{
static void Main()
{
bool[] blns = { true, false, true, false, true };
Console.WriteLine(blns.Count());
Console.WriteLine(blns.Count(bln => bln == true));
Console.WriteLine(blns.Count(bln => bln == false));
}
}
실행 결과
5 3 2
Count() 메서드에 Count(bln => bln == true) 형태로 Where() 메서드를 호출하지 않고 바로 조건에 맞는 데이터 개수를 구할 수 있습니다.