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

EqualsAny

Check that the given string is in a list of potential matches. Inspired by StackOverflow answer http://stackoverflow.com/a/20644611/23199

Source

public static bool EqualsAny(this string str, params string[] args) 
{ 		
    return args.Any(x=> 
      StringComparer.InvariantCultureIgnoreCase.Equals(x, str));		
}

Example

string custName = "foo";
bool isMatch = (custName.EqualsAny("bar", "baz", "FOO")); //true

Author: Phil Campbell

Submitted on: 17 dec. 2013

Language: C#

Type: System.String

Views: 7846