Variable parameters in C# Lambda

前端 未结 5 1281
别跟我提以往
别跟我提以往 2021-01-01 23:07

Is it possible to have a C# lambda/delegate that can take a variable number of parameters that can be invoked with a Dynamic-invoke?

All my attempts to use the \'par

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 23:34

    No, but with a little help, you can almost fake it:

    object[] Params(params object[] args) { return args;}
    
    // :
    
    Action CWL = 
                      (format,  args) => Console.WriteLine(format, args);
    
    CWL("{0}, {1}", Params(1,2));
    

提交回复
热议问题