Adding C# solution.
[IEnumerableExtras.git] / C# / EnumerableFilter.cs
blob51382d20955c4e4f4624545ed0c85175e66292dc
1 using System;
2 using System.Collections.Generic;
4 namespace IEnumerableExtras
6 /// <summary>
7 /// Provides <see cref="IEnumerable{T}"/> Filter extension.
8 /// </summary>
9 public static class EnumerableFilter
11 /// <summary>
12 /// Filter out those items in this collections that don't satisfy <paramref name="filterFunc"/>.
13 /// </summary>
14 /// <typeparam name="T">/typeparam>
15 /// <param name="collection"></param>
16 /// <param name="filterFunc"></param>
17 /// <returns></returns>
18 public static IEnumerable<T> Filter< T >( this IEnumerable<T> collection, Func<T, bool> filterFunc )
20 foreach ( T item in collection )
22 if ( filterFunc( item ) )
24 yield return item;