I have lots of functions, But I do need to run them inside another function.
I know I can do something like this
public void Method1()
{
bla bla
}
public void Method2()
{
bla bla
}
public void Wrapper(Action<string> myMethod)
{
method{
myMethod()
}
bla bla
}
And then call them using something like this:
wrapper(Method1());
The issue is tha sometimes I need to run Method1, and Method2, at the same time. They are a lot.
Sometimes One, sometimes several at the same time.
So I am thinking that would be great to do something like this:
Wrapper({bla bla bla; method(); bla bla; }
{
method{
bla bla bla;
method();
bla bla;
}
}
Run a code block inside a method, and the parameter of the method is the code block.
Do you think is it possible or would you recommend another approach?
Having
you may specify
myMethodusing lambda expression:That is you don’t need to explicitly define a method with the desired signature (here matching
Action<string>), but you may write inline lambda expression, doing whataever you need.From MSDN: