Set multiple properties in a List ForEach()?

后端 未结 5 912
感情败类
感情败类 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:22

    Anonymous method is your friend

    list.ForEach(item => 
                  { 
                      item.a = "hello!"; 
                      item.b = 99; 
                  }); 
    

    MSDN:

    • Anonymous Methods (C# Programming Guide)

提交回复
热议问题