Let's break this down.
Your Func Func<string, T>
method is expecting a function which accepts a string
parameter and returns a T
.
When you initialise that Func<string, T>
with x => MethodToInvoke(myVal)
you are saying:
"Here's a function with a parameter called x
which is implemented by calling MethodToInvoke(myVal)
, and the return type is whatever type MethodToInvoke()
returns."
Although that function has a parameter called x
, you are NOT actually using it on the right of the =>
because you are using myVal
instead.
To fix it, use the x
like so (and also add myVal
as an extra parameter):
Step(x => MethodToInvoke(x), myVal);
Which can be simplified to:
Step(MethodToInvoke, myVal);
Then you will need to change your Step()
method to take an additional string parameter and pass it to the Func that is also passed to Step():
T Step<T>(Func<string, T> method, string str)
{
return method.Invoke(str);
}
Which can also be simplified to:
T Step<T>(Func<string, T> method, string str)
{
return method(str);
}