Created
April 24, 2012 08:40
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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