0

Assuming I have a method like this (my actual method does more—I've simplified the code here):

protected void Run(Action a)
{
    a();
}

I can then call it with code like this:

Run(myAction);

But how would I create an inline method to pass arguments to my action. The following code produces an invalid argument error:

Run(myAction(arg1, arg2));

I'm accustomed to doing this with actions that are passed an argument using a lambda expression like arg => myAction(arg), but here no argument is passed. So what would be the proper syntax?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466

1 Answers1

4
 Run(()=>myAction(arg1, arg2));
I4V
  • 34,891
  • 6
  • 67
  • 79