Wilsonhut

Deal with it or don't

.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

CollectionOfThings.WhereNot(ThingMeetsSomeCondition)

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: