ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Returns true if this string is any of the provided strings. Equivalent to IN operator in SQL. It eliminates the need to write something like 'if (foo == "foo1" || foo == "foo2" || foo == "foo3")'


public static bool In(this string s, params string[] values)
   return values.Any(x => x.Equals(s));


if (product.Category.In("Electronics", "Computers")
   // do something

Author: Ivan Ferić

Submitted on: 22 okt. 2010

Language: C#

Type: System.String

Views: 4952