If I have a list of objects that have the properties fruitName
and numFruits
and I want to pluralize the fruitName
where numFruits
is greater than 1, is it possible to do that in a single statement by chaining together Where
and Foreach
?
Something like:
fruitList.Where(fl => fl.numFruits > 1).ForEach(fl => fl.fruitName = fl.fruitName + "s");
I tried the above and it doesn't work. It complains that System.Collections.Generic.IEnumerable doesn't contain a definition for ForEach.