传递一个拉姆达与不同参数的方法拉姆、不同、参数、方法

2023-09-06 07:57:48 作者:爸,詯崾娶她

是否有可能调用传递一个拉姆达与可变数量的参数的方法?

Is it possible to call a method passing a lambda with variable number of parameters?

例如:

public void Go(Action x)
{
}

我需要调用它传递参数,如:

I need to call it passing parameters, such as:

Go(() => {});
Go((x, y) => {});
Go((x) => {});

这可能吗?怎么样?

Is it possible? How?

推荐答案

您可以在

public void Go<T>(Action<T> x)
{
}

这是一篇文章显示 动作&LT更多的例子; T&GT; 。请注意,它不返回一个值,从MSDN:

Here is an article showing more examples of Action<T>. Notice that it doesn't return a value, from MSDN:

封装,有一个方法   单参数,不返回   值。

Encapsulates a method that has a single parameter and does not return a value.

 
精彩推荐