Error when using .Contains to check if a string contains a character
asp.net-mvc, asp.net-mvc-3, c#
Solution
And it's write: `string.Contains` doesn't have an overload taking just a single character.
Options:
- Use `@ViewBag.Options.Contains("q")`
- Use `@ViewBag.Options.IndexOf('q') != -1`
- Use some more complicated LINQy approach (e.g. `Any`) - 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)
- Use some more complicated regular expression approach - again, there's no point.
Problem
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.