Implement the “Where” method in C#

Technology CommunityCategory: C#Implement the “Where” method in C#
VietMX Staff asked 3 years ago

Consider:

public static IEnumerable<T> Where<T>(this IEnumerable<T> items, Predicate< T> prodicate)
{
  foreach(var item in items)
  {
      if (predicate(item))
      {
           // for lazy/deffer execution plus avoid temp collection defined
           yield return item;
      }
  }
}