You can do it:
foo.ForEach(x => { selectedIds.Add(x.Id); aggregateContent += x.Content; });
I would recommend not concatenating Content into a string, but rather using StringBuilder .
EDIT
If you don't have a LINQ extension library that implements ForEach for IEnumerable , here is the method you can use:
public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action) { foreach(T item in enumeration) { action(item); } }
Roy dictus
source share