函数编程和LINQ [英] Functional programming and LINQ
本文介绍了函数编程和LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我正在阅读CodeProject的优秀文章之一
我遇到了以下代码行的麻烦:
< pre lang =C#> string [] names = new string [] { test1, test2};
Predicate< string> longWords = 委托(字符串字){ return word.Length > 4 ; };
int numberOfBooksWithLongNames = names.Count(longWords);
编译器错误CS1928和CS1503在最后一行。
这是我的石器时代C#编译器(VS2010)还是出了什么问题?
提前谢谢
解决方案
将Predicate< string>
更改为Func< string,bool>
。
Linq 方法计数
定义为;
public static int Count< TSource>(此IEnumerable< TSource>源,Func< TSource,bool>谓词);
希望这会有所帮助,
Fredrik
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
解决方案
ChangePredicate<string>
toFunc<string, bool>
.
The Linq methodCount
is defined as;
public static int Count<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
Hope this helps,
Fredrik
这篇关于函数编程和LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文