Set multiple properties in a List ForEach()?

后端 未结 5 911
感情败类
感情败类 2021-01-30 05:04

Given a class:

class foo
{
    public string a = \"\";
    public int b = 0;
}

Then a generic list of them:

var list = new List         


        
5条回答
  •  有刺的猬
    2021-01-30 05:34

    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; });
    

提交回复
热议问题