Working With The Collection Extension Methods (3 of 3)

Review In Part 2, we took a peek at the Zip method. posh> [System.Linq.Enumerable]::Zip OverloadDefinitions ------------------- static System.Collections.Generic.IEnumerable[TResult] Zip[TFirst, TSecond, TResult](System.Collections.Generic.IEnumerable[TFirst] first, System.Collections.Generic.IEnumerable[TSecond] second, System.Func[TFirst,TSecond,TResult] resultSelector) Play That Func-y Music You may have heard a Func in C# called an anonymous function or a lambda. In the MSDN example, it looks like this. var totalCommission = quarterlySales.Zip(quarterlyRate, (first, second) => first * second).Sum(); In C#, the Zip method is a member of a Collection and in the above example, they are calling the Zip method of quarterlySales collection and passing in the quarterlyRate collection as well as the lambda expression.

Working With The Collection Extension Methods (2 of 3)

Predicates Okay. So, we have this collection. posh> $list Mike Bob Wendy Michele Which has a method called FindAll that takes a Predicate. posh> $list.FindAll OverloadDefinitions ------------------- System.Collections.Generic.List[string] FindAll(System.Predicate[string] match) What is a predicate? WikiPedia simply puts it like this. A predicate is a statement that may be true or false depending on the values of its variables If you’ve written some SQL in your life, a Where clause is a predicate.

Working With The Collection Extension Methods (1 of 3)

Sometimes, when you’re working with some data, you want a little bit more functionality or performance than you get from the run of the mill arrays. This is the first in a series of posts about [System.Collections.Generic.List]. Introductions First things first, Generic Lists are statically typed. PS C:\Temp> $list = New-Object System.Collections.Generic.List[int] PS C:\Temp> $list.add(1) PS C:\Temp> $list.add("two") Cannot convert argument "item", with value: "two", for "Add" to type "System.