Set multiple properties in a List ForEach()?

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

    list.ForEach(i => i.DoStuff());
    public void DoStuff(this foo lambda)
    {
      lambda.a="hello!"; 
      lambda.b=99;
    }
    

提交回复
热议问题