c# - 具有四个以上参数(方法参数)的 Action 委托(delegate)

标签 c# delegates

我写了一个辅助类,它使用 Action - delegate 作为方法参数。
像这样:
public void SomeMethod(Action<T> methodToExecute, T argument);

根据 MSDN,您可以声明最大值。 Action 委托(delegate)的 4 个参数:Action<T1,T2,T3,T4> .

现在我想调用一个需要 5 个的方法!争论。我怎么能这样做?
最好的解决方案是我可以使用动态数量的方法参数。

谢谢

最佳答案

声明你需要的 Action 委托(delegate),这没什么神奇的:

public delegate void Action<T1, T2, T3, T4, T5>(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5);

关于c# - 具有四个以上参数(方法参数)的 Action 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1410446/

相关文章:

c# - 如何将通过反射获得的方法分配给委托(delegate)? (或 : how to speed up method calls through reflection)

c# - 什么是 MapTimeZoneId 的 Noda Time 2.0 等价物?

c# - AES 解密仅产生部分答案 C#

c# - MVVMCross,FieldBinding 插件,iOS,代码绑定(bind)不起作用

ios - setDelegate解释

c# - 如何在调用方法中定义回调函数?

c# - 如何用\"修复JSON?

c# - Xamarin 表格 : Bind byte array to ImageCell ImageSource in ListView

c# - 有没有办法将函数及其参数存储在变量中以供以后调用?

c# - 泛型/委托(delegate)和带参数的传递函数