public class DemoAction
{
public Action action;
public Action<int> action1;
public Action<int,string> action2;
public Action<List<int>> action3;
/// <summary>
/// 不带参数
/// </summary>
public void ActionDemo()
{
if (action != null)
{
action();
}
}
/// <summary>
/// 带一个参数
/// </summary>
/// <param name="a"></param>
public void ActionDemo(int a)
{
if (action1 != null)
{
action1(a);
}
}
/// <summary>
/// 带两个参数
/// </summary>
/// <param name="a"></param>
/// <param name="str"></param>
public void ActionDemo(int a,string str)
{
if (action2 != null)
{
action2(a,str);
}
}
/// <summary>
/// 带一个列表
C#之Action的实际应用例子
最新推荐文章于 2024-07-21 18:49:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)