All you need to do is introduce some brackets so that your anonymous method can support multiple lines:
list.ForEach(i => { i.a = "hello!"; i.b = 99; });
Anonymous method is your friend
list.ForEach(item =>
{
item.a = "hello!";
item.b = 99;
});
MSDN:
list.ForEach(lamba=>lambda.a="hello!");
Becomes
list.ForEach(item=>{
item.a = "hello!";
item.b = 99;
});
Of course you can also assign them when you create the list like :
var list = new List<foo>(new []{new foo(){a="hello!",b=99}, new foo(){a="hello2",b=88}});
list.ForEach(i => i.DoStuff());
public void DoStuff(this foo lambda)
{
lambda.a="hello!";
lambda.b=99;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With