Deal with it or don't

Monthly Archives: July 2011

.Where? .WhereNot

Ever have some code like this?

CollectionOfThings.Where(x => !ThingMeetsSomeCondition(x))

If only there were a WhereNot method, then you could use it with a method group, like so


So Where is your WhereNot? Here:

  public static class Extensions


    public static IEnumerable<T> WhereNot<T>(this IEnumerable<T> items, Func<T, bool> predicate)


      return items.Where(x => !predicate(x));




Glad that’s done.