Skip to content

Instantly share code, notes, and snippets.

@alibaabaa
Created April 24, 2012 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alibaabaa/2477970 to your computer and use it in GitHub Desktop.
Save alibaabaa/2477970 to your computer and use it in GitHub Desktop.
Adds direct predicate support to ToList() to avoid LINQ chaining on Func(x).ToList()
/// <summary>
/// Adds direct predicate support to ToList() to avoid
/// linq chaining on Func(x).ToList()
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static List<T> ToList<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
List<T> result = new List<T>();
foreach (T item in source)
if (predicate.Invoke(item))
result.Add(item);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment