Itβs good that I wonβt write code this way at all, but you can just use the lambda operator:
The lambda operator resembles the expression lambda, except that the operator is enclosed in braces
The body of a lambda statement can consist of any number of statements; however, in practice, usually no more than two or three.
Thus, the ForEach call will look like this:
.ForEach(x => { x.BtnColor = Color.Red.ToString(); x.OtherColor = Color.Blue.ToString(); });
I would write a ForEach loop instead:
var itemsToChange = objFreecusatomization.AllCustomizationButtonList .Where(p => p.CategoryID == btnObj.CategoryID && p.IsSelected && p.ID == btnObj.ID); foreach (var item in itemsToChange) { item.BtnColor = Color.Red.ToString(); item.OtherColor = Color.Blue.ToString(); }
(You can embed the query in a ForEach statement, but I personally find the above approach using a separate local variable cleaner.)
source share