I have this piece of code, that takes a single function with no parameter, and return's its runtime.
public static Stopwatch With_StopWatch(Action action)
{
var stopwatch = Stopwatch.StartNew();
action();
stopwatch.Stop();
return stopwatch;
}
I would like to transform it to take non void functions with parameters. I heard about the Func<> delegate, but I have no idea how to use it. And I need something like this (very pseudo) :
public T measureThis(ref Stopwatch sw, TheFunctionToMeasure(parameterA,parameterB))
{
sw.Start(); // start stopwatch
T returnVal = TheFunctionToMeasure(A,B); // call the func with the parameters
stopwatch.Stop(); // stop sw
return returnVal; // return my func's return val
}
So I have to get the return value of the passed func, AND get the stopwatch in the end. Any help is greatly appreciated!