I have a string
String input = "nbfs;jlt;\"";
With this string I use .Contains<>()
if (input.Contains<String>("nbfs;jlt;"))
{
Console.WriteLine("True");
}
also
if (input.Contains("nbfs;jlt;"))
{
Console.WriteLine("True");
}
does not work.
Why does the above if statement return false?
input.Contains<String>("nbfs;jlt;")is expecting an enumeration of strings.use:
input.Contains("nbfs;jlt;")EDIT
In response to the many comments, the
.Contains<T>method will not compile on a standard string:The
.Contains<T>method is expecting some type of enumerable input such as the following to compile:Given that the OP is saying the code compiles, I would suggest opening a new Console Project and start from scratch. And type everything, do not copy/paste.
On a side note: There may be some odd entity characters hidden when you copy/paste from files, so that may be one reason why the Contains method will not work on your string.
Edit 2
This will compile and return true based on your sample strings. Copy/Paste this into a console app and be sure not to include any assemblies other than the default ones with the Console app: