我刚开始使用LINQ,我遇到了一些麻烦。
说我想做这样的事情:
IEnumerable<String[]> = from s in listOfStrings where () => { int sum = 0; for (int i=0; i<s.Length(); i++) { sum += s[i]; } return sum < 50; } select () => { String[] t = new String[s.Length()]; for (int i=0; i<s.Length(); i++) { t[i] = s[i].toString(); } return t; }基本上我想从listOfStrings中的字符串中获取一个字符数组作为字符串值,其总和小于50。
这只是一个例子,很难想到一个更无用的函数吧,我只是想知道如何在linq中的lambda函数中执行东西,而不需要创建一个新的函数。
谢谢!
I'm just getting started with LINQ, and I'm having some troubles.
Say I wanted to do something like this:
IEnumerable<String[]> = from s in listOfStrings where () => { int sum = 0; for (int i=0; i<s.Length(); i++) { sum += s[i]; } return sum < 50; } select () => { String[] t = new String[s.Length()]; for (int i=0; i<s.Length(); i++) { t[i] = s[i].toString(); } return t; }Basically I want to get an array of characters as string values in from strings in listOfStrings that have a sum smaller than 50.
This is just an example though, It would be hard to think of a more useless function huh, I'm just trying to find out how to execute stuff in lambda functions within linq, without making a new function to do it.
Thanks!
最满意答案
如果使用方法链接语法而不是查询语法(即listOfStrings.Where(...) ),则可以将lambda放在那里。
If you use the method-chaining syntax instead of the query syntax (i.e. listOfStrings.Where(...)), you can stick the lambda in there.
更多推荐
发布评论