Lambda Expression without Argument

471 views Asked by At

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?

1

There are 1 answers

1
I4V On BEST ANSWER
 Run(()=>myAction(arg1, arg2));