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!
If you use the method-chaining syntax instead of the query syntax (i.e.
listOfStrings.Where(...)), you can stick the lambda in there.