Jamie Dixon
Web Developer, Software Engineer and Mixed Language Artist
-
ContainsAny & EquelsAny
Posted on November 2nd, 2010 No commentsThis post is a bit of a reference for myself and also a handy tip for those wondering how to perform Contains and Equels on a collection of strings.
For the purposes I needed I simply wanted to check if a string Equels Any or Contains Any of an array of strings. I put these together as a couple of extension methods:
public static bool ContainsAny(this string input, string[] items) { return items.Any(input.Contains); }
public static bool EqualsAny(this string input, string[] items) { return items.Any(input.Equels); }
That’s all that’s required.
This means we can now do things like:
bool isWomenOrUnisex = category.EquelsAny(new []{"women","unisex"});
Simples!
Leave a reply


