The Contains(...) method for string is case-sensitive. I’d like to override it in order to make it case-INsensitive with the following code (which is stolen from here):
public static bool Contains(this string source, string toCheck, StringComparison comp)
{
return source.IndexOf(toCheck, comp) >= 0;
}
However, I don’t know where the code should be pasted. Should it be placed inside the same namespace of the class program? Does it need a dedicated class?
If what you are intending is to create an extension method for the
stringclass, then you need to put it inside some class. To use it, simply make sure you have ausingstatement specifying a reference to the namespace containing the class.For example: