I am new to Linq.
I want to set two values in foreach
statement like this
My actual code is this
foreach (Employee emp in employees)
{
foreach(Department dept in emp.Departments)
{
dept.SomeProperty = null;
}
collection.AddRange(emp.Departments);
}
Little refactoring turns the above into this
foreach (Employee emp in employees)
{
emp.Departments.ToList().ForEach(u => u.SomeProperty = null))
collection.AddRange(emp.Departments);
}
But I want something like this
employees.ToList().Foreach(collection.AddRange(emp.Departments),
emp.Departments.ToList().ForEach(u => u.SomeProperty = null))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…