我需要获得满足我的条件的字符串[]中指定的项目数。所以,我尝试了Predicate并使用相同的方法定义了我的状态。但我的代码不起作用。谁能帮帮我吗?使用谓词计数单词
string[] books = new string[] { "Java", "SQL", "OOPS Concepts", "DotNet Basics"};
Predicate<string> longBooks = delegate(string book) { return book.Length > 5; };
int numberOfBooksWithLongNames = books.Count(longBooks);
当我运行它时,它显示编译时错误。请参考下面:
“串[]”不包含“计数”和最佳的扩展方法过载“System.Linq.Enumerable.Count(System.Collections.Generic.IEnumerable,System.Func定义)”有一些无效参数
请加德泰ls为什么它不起作用 – CharlesB
我已经编辑过你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –
而不是像这样使用匿名委托,你可以使用lambda'books.Count(book => book.Length> 5)''''''''' –