List Foreach parameterized delegate

前端 未结 2 2003
清歌不尽
清歌不尽 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<string> documents = GetAllDocuments();
    documents.ForEach( d => CallAnotherFunction(d, "some content") );
    
    List<string> templates = GetAllTemplates();
    templates.ForEach( t => CallAnotherFunction(t, "other content") );
    
    0 讨论(0)
  • 2021-01-14 07:18

    Use lambda expression:

    string content = "Other parameter value";
    documents.ForEach(x => CallAnotherFunction(x, content));
    
    0 讨论(0)
提交回复
热议问题