开发者

Passing a function with arguments to a delegate expecting none

I know in Python you can use functools.partial to pass a function object with some or all of the parameters already defined.

Is there a way to do this in C#? I would like to do the following: class1.MethodTakingAMethodParameter(3, "foo", class1.MethodToPa开发者_Python百科ss(param1, param2, param3));

For a delegate like delegate void Blah().


You can use lambdas to give some parameters a value:

Action paramlessDelegate = ()=>MyFunc(value1,value2,value3)

Or if you want to only put a value into some params:

Action<int> oneParamDelegate = (remainingParam)=>MyFunc(value1, remainingParam, value3)

In your example:

class1.MethodTakingAMethodParameter(3, "foo", ()=>class1.MethodToPass(param1, param2, param3));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜