I have a list that holds a few strings(names). For this example. It will hold:
And I'm trying to check if that list has one of those. And I'm doing this like this at the moment:
if (list.Contains(test2))
{
}
But I need it to be case insensitive.. But how can I do that? in an if statement.
The Contains method has an overload that accepts an IEqualityComparer. You can give it one by doing the following:
if (list.Contains(test2, StringComparer.OrdinalIgnoreCase))
{
// do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With