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>
/// 带一个列表
/// </summary>
/// <param name="?"></param>
public void ActionDemo(List<int> list){
if (action3 != null)
{
action3(list);
}
}
}

public class CSharpDemo : MonoBehaviour {

Action action;

// Use this for initialization
void Start () {

DemoAction demo = new DemoAction();
demo.action = TestAction;
demo.action1 = TestAction;
demo.action2 = TestAction;
demo.action3 = TestAction;

List<int> list = new List<int>(){10,20,30,40};
demo.action();
demo.action1(20);
demo.action2(20, "rose_grils");
demo.action3(list);

}

// Update is called once per frame
void Update () {

}

/// <summary>
/// 不带参数
/// </summary>
void TestAction(){
Debug.LogError(" 不带参数");
}

/// <summary>
/// 带一个参数
/// </summary>
/// <param name="a"></param>
void TestAction(int a)
{
Debug.LogError("带一个参数 = " + a);
}

/// <summary>
/// 带2个参数
/// </summary>
/// <param name="a"></param>
/// <param name="str"></param>
void TestAction(int a, string str)
{
Debug.LogError("带2个参数a = " + a + " str = " + str);
}

/// <summary>
/// 带一个列表
/// </summary>
/// <param name="list"></param>
void TestAction(List<int> list)
{
Debug.LogError("带一个列表");
for (int i = 0; i < list.Count; i++)
{
Debug.LogError("i = " + list[i]);
}
}

}

运行结果如下图:

---------------------
作者:穿梭在26个字母的世界
来源:CSDN
原文:https://blog.csdn.net/rose_girls/article/details/50152823

C#之Action的实际应用例子的更多相关文章

  1. Struts2学习笔记 - Action篇<定义逻辑Action>

    有三种方法可以使一个Action处理多个请求 动态方法调用DMI 定义逻辑Acton 在配置文件中使用通配符 这文章就谈论一下定义逻辑Action 这里主要关注的是struts.xml配置文件,一般情 ...

  2. [C#基础]Func和Action学习

    目录 委托 Action Func 总结 委托 委托的那些事 关于委托的基本定义,在很久之前的这篇文章中,有个简单的介绍.稍微回顾一下. 委托是c#中类型安全的,可以订阅一个或多个具有相同签名方法的函 ...

  3. React学习(2)——action,reducer

    action creator 是一个函数,格式如下: var actionCreator = function() { // 构建一个 action 并返回它 return { type: 'AN_A ...

  4. Salesforce Consumer Goods Cloud 浅谈篇三之 行动计划(Action Plan)相关配置

    本篇参考: https://v.qq.com/x/page/f0772toebhd.html https://v.qq.com/x/page/e0772tsmtek.html https://v.qq ...

  5. Oozie分布式任务的工作流——邮件篇

    在大数据的当下,各种spark和hadoop的框架层出不穷.各种高端的计算框架,分布式任务如乱花般迷眼.你是否有这种困惑!--有了许多的分布式任务,但是每天需要固定时间跑任务,自己写个调度,既不稳定, ...

  6. 【基础】MVC路由规则

    一.RouteData解析过程 在ASP.NET MVC中,服务器收到来自客户端的请求后,会经过一些列的处理拿到请求的数据,比如在Pipeline 管线事件中,通过订阅适当的事件,将HttpConte ...

  7. ASP.NET MVC 5 - 控制器

    MVC代表: 模型-视图-控制器 .MVC是一个架构良好并且易于测试和易于维护的开发模式.基于MVC模式的应用程序包含: · Models: 表示该应用程序的数据并使用验证逻辑来强制实施业务规则的数据 ...

  8. Circuit Breaker Pattern(断路器模式)

    Handle faults that may take a variable amount of time to rectify when connecting to a remote service ...

  9. Struts2 - Conversion Plugin

    转载:http://www.cnblogs.com/ikuman/archive/2013/11/04/3403073.html 1.struts2自2.1以后推荐使用Convention Plugi ...

随机推荐

  1. LeetCode 922 Sort Array By Parity II 解题报告

    题目要求 Given an array A of non-negative integers, half of the integers in A are odd, and half of the i ...

  2. scala-泛型

    //实例化之后使用get方法必须传入相同类型的参数 class A[T](x: T) { def get(x: T) { print(x) } } var a1 = new A(1) a1.get(1 ...

  3. webstorm 2017激活

    选择“license server” 输入:http://idea.imsxm.com/

  4. mysql 权限管理 目录

    mysql 权限管理介绍 mysql 权限管理 记录 mysql 权限管理 grant 命令 mysql 权限管理 revoke 回收权限 命令 mysql 权限管理 针对库 授权 db.* mysq ...

  5. mysql mpm

    mysql mpm 参考文章 http://www.myexception.cn/mysql/1968274.html http://www.linuxidc.com/Linux/2013-07/86 ...

  6. js计算常见操作

    如何实现数字相加 var a = 1, var b = 2, var c = a + b 这样c得出来的解果是12, 使用Number()函数可以解决这个问题,如下 var c = Number(a) ...

  7. python进制转换及变量

    .编译型语言和解释型语言的区别? 答: () 编译型语言:是将所有源码编译完成二进制后才进行输出,运行快,执行效率高,时间周期长. ()解释型语言:逐行编译输出,执行效率相对慢,开发效率高, .Pyt ...

  8. [LeetCode] 105. Construct Binary Tree from Preorder and Inorder Traversal_Medium tag: Tree Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  9. javascript另类方法高效实现htmlencode()与htmldecode()函数

    最常见的做法是采用正则表达式替换的方法,将特殊字符如 < > & 等进行替换,htmlencode的时候这样替换还比较容易,但发过来htmldecode的时候就不一定好用了,因为需 ...

  10. ICSharpCode.TextEditor使用及扩展

    SharpDevelop (#develop)有很多“副产品”,其中最出名的应算SharpZipLib (#ziplib),纯C#的ZIP类库,而在SharpDevelop (#develop)中,“ ...