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

In

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")'

Source

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

Example

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

Author: Ivan Ferić

Submitted on: 22 okt 2010

Language: C#

Type: System.String

Views: 4889