Click here to Skip to main content
14,767,619 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
At the moment I am reading one of the excellent articles of CodeProject
and I have troubles with code lines like:

string[] names = new string[] {"test1", "test2"};

Predicate<string> longWords = delegate(string word) { return word.Length > 4; };
int numberOfBooksWithLongNames = names.Count(longWords);


Compiler errors CS1928 and CS1503 in the last line.

Is it my stone-age C# compiler (VS2010) or what is going wrong?

Thanks in advance
Posted

1 solution

Change Predicate<string> to Func<string, bool>.
The Linq method Count is defined as;
public static int Count<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);

Hope this helps,
Fredrik
   
v2
Comments
sja63 21-Feb-13 9:53am
   
I have already included your recommended line.
This cannot be the reason.
Best regards.
Fredrik Bornander 21-Feb-13 9:57am
   
Sorry, I was too quick to reply, I've fixed my answer now.
sja63 21-Feb-13 10:04am
   
Thank you. It works now.
Fredrik Bornander 21-Feb-13 10:06am
   
Glad I could help, sorry about the first c***-up.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900