Reputation: 32828
I have this code:
var webWordForms = rootObject.webWordForms
.Where(w => w.definition != null)
.ToList();
foreach (var webWordForm in rootObject.webWordForms)
{
processWordForm(word, webWordForm);
}
Is there a way that I can combine these two statements and call processWordForm from inside the first statement?
Upvotes: 1
Views: 35
Reputation: 158
Use a ForEach
extension on List<T>
For example,
rootObject.webWordForms
.Where(w => w.definition != null)
.ToList()
.ForEach(webWordForm => processWordForm(word, webWordForm));
Upvotes: 4
Reputation: 16956
You could use ForEach
method of List to chain your operation, but it is not different than what you are already doing.
tObject.webWordForms
.Where(w => w.definition != null)
.ToList()
.ForEach(wordForm => processWordForm(word, wordForm));
Upvotes: 1