How do I pass a method as the parameter of another method using linq expressions

c#, expression, func, linq

Solution

If your method has return value use Func delegate otherwise you can use Action delegate. e.g:

void Method1(string param)
{
    // Some Code
}

void Method2(string param)
{
   // Some Code
}

void RunInThread(Action<string> m)
{
   //Run the method in a background thread
}

Then you can call `RunInThread` this way:

RunInThread(Method1);
RunInThread(Method2);

Problem

I want to create a method that runs another method in a background thread. Something like this: ``` void Method1(string param) { // Some Code } void Method2(string param) { // Some Code } void RunInThread(AMethod m) { //Run the method in a background thread } ```

Original source