List Foreach parameterized delegate

前端 未结 2 2085
清歌不尽
清歌不尽 2021-01-14 06:37

I am trying to invoke a function for every member of a list, but pass additional parameters to the delegate.

if I have a list called documents



        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 07:12

    Use lambda expressions instead of method groups:

    List documents = GetAllDocuments();
    documents.ForEach( d => CallAnotherFunction(d, "some content") );
    
    List templates = GetAllTemplates();
    templates.ForEach( t => CallAnotherFunction(t, "other content") );
    

提交回复
热议问题