My object hierarchy is like this:
class Detail
{
public List<Row> Rows { get; set; }
}
class Row
{
public List<Column> Columns { get; set; }
}
class Column
{
public string Name { get; set; }
public bool IsUpdated { get; set; }
}
I want to set column.IsUpdated = true where column.Name = “id”.
I am trying this, it doesn’t work.
detail.Rows.ForEach(r => r.Columns.Where(c => c.Name.ToLower().Equals("id")).ToList<Column>().Select(c => c.IsUpdated = true));
The philosophy of LINQ is to not have side effects. That’s why on purpose it does not make it easy for you to do this. You could do it either with a classic
or by using
List.ForEach, but in a different manner: