.네트 확장 멤버 쉬운 설명
예를 들어 System.Linq.Enumerable.Count()는 List.Count 프라퍼티처럼 이뉴머러블 엘리먼트들의 수를 반환한다. 하지만 후자와 달리 조건을 붙일 수 있다.
int count = Stocks.Count(s => s.Managed);
링큐로 가능한 메떠드를 레거시 컬렉션도 쓸 수 있게 한다. 그래서 확장 메떠드라 한다.
Count<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)
예가 문법을 따르지 않았지만 제대로 작동한다. 문법을 따른 예는 이렇다.
int count = Enumerable.Count(Stocks, s => s.Managed);
앞의 예가 뒤의 그것보다 편하다.
Extension methods are static methods, but they’re called as if they were instance methods on the extended type.
Extension members
스태틱으로 이미 만들어 놓은 메떠드이므로 따로 인스턴스를 만들 필요 없이 바로 불러서 쓸 수 있다. 게다가 마치 레거시 컬렉션the extended type의 메떠드인 거처럼 쓸 수도 있다.