I am trying to find out if a string contains a character. I tried the following
where ViewBag.Options is a string:
@ViewBag.Options.Contains('q')
but it gives me an error saying:
The best overloaded method match for ‘string.Contains(string)’ has some invalid arguments.
And it’s write:
string.Containsdoesn’t have an overload taking just a single character.Options:
@ViewBag.Options.Contains("q")@ViewBag.Options.IndexOf('q') != -1Any) – feasible, but there’s no need here. (I’m a fan of LINQ where appropriate but I don’t think that’s the right approach here; I wouldn’t start introducing lambda expressions into my code just for the sake of it)