How is the long method way of doing below code in "Lambda Expressions" in the past?
public static IEnumerable<T> Get<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
foreach (T item in source)
{
if 开发者_开发技巧(predicate(item))
yield return item;
}
}
Like this:
public static IEnumerable<T> Get<T>
(IEnumerable<T> source, Func<T, bool> predicate)
{
var list = new List<T>();
foreach (T item in source)
{
if (predicate(item))
{
list.Add(item);
}
}
return list;
}
精彩评论