I am using C#, WinForms, In VS2010 Pro and trying to run one line of code:
var count = before.Count(c => c == '/');
which I got from here: How would you count occurrences of a string within a string?
but it doesn’t recognize Count method on Strings, so it gives error and doesn’t compile.
How should I fix it? what is missing?
Most likely, you are missing a using directive for the
System.Linqnamespace or less likely, a reference to theSystem.Core.dllassembly.Try inserting this at the top of your file:
If that doesn’t fix it, right-click on your project from “Solution Explorer”, choose “Add Reference” from the context-menu and then ensure that
System.Core.dllis referenced.Also ensure that you are targeting .NET 3.5 or later (there are workarounds for .NET 2.0, such as LinqBridge).