Multiple string comparison with C#
Use Enumerable.Contains<T>
which is an extension method on IEnumerable<T>
:
var strings = new List<string> { "A", "B", "C" };
string x = // some string
bool contains = strings.Contains(x, StringComparer.OrdinalIgnoreCase);
if(contains) {
// do something
}
if ((new[]{"A","B","C"}).Contains(x, StringComparer.OrdinalIgnoreCase))