The original idea of LINQ is not to modify existing collections, but to return new ones, so methods like ForEach
are not among the default LINQ methods.
You could easily write your own ForEach like:
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var item in source)
action(item);
}
and so your code would become:
dgv.Columns.Cast<DataGridViewColumn>.ForEach(col=>col.ReadOnly=true);
BTW...
it is really worthwhile writing it as LINQ extension, when with 2 lines of old imperative-school code you can do the same ?
foreach (DataGridViewColumn col in this.dataGridView1.Columns)
col.ReadOnly = true;