委托
来源:互联网 发布:淘宝标题自动优化软件 编辑:程序博客网 时间:2024/06/04 19:07
Action是无返回值的泛型委托。
Action 表示无参,无返回值的委托
Action<int,string> 表示有传入参数int,string无返回值的委托
Action<int,string,bool> 表示有传入参数int,string,bool无返回值的委托
Action<int,int,int,int> 表示有传入4个int型参数,无返回值的委托
Action至少0个参数,至多16个参数,无返回值。
using UnityEngine;
using System.Collections;using System;
public class TestAction : MonoBehaviour {
// Use this for initialization
void Start () {
Test<string> (Action, "字符串"); //T-string >> 字符串
Test<int> (Action, 1000); //T-int >> 1000
Test<string> (p => {Debug.Log("lambda表达式定义委托 >> " + p);}, "我用的是表达式");//lambda表达式定义委托 >> 我用的是表达式
}
void Test<T>(Action<T> action, T p)
{
action (p);
}
void Action(string s)
{
Debug.Log ("T-string >> " + s);
}
void Action(int s)
{
Debug.Log ("T-int >> " + s);
}
}
delegate
delegate我们常用到的一种声明
Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型。
using UnityEngine;
using System.Collections;
public delegate int MethodDelegate(int x, int y);
public class TestDelegate : MonoBehaviour {
private MethodDelegate method;
// Use this for initialization
void Start () {
method = new MethodDelegate (Add);
Debug.Log (method(10, 20));//30
}
int Add(int x, int y)
{
return x + y;
}
}
相关文章:http://www.cnblogs.com/akwwl/p/3232679.html
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 委托
- 实验c++2-1(上机报告)
- simple webcrawler 初步理解
- Android屏幕适配全攻略(最权威的官方适配指导)
- 验证ORACLE不同字符集中汉字占用的byte及NLS_LENGTH_SEMANTICS参数的影响
- Unity的二进制热更新 (二)unity的运行原理
- 委托
- 建议性锁和强制性锁
- ubuntu下配置opencv
- OC阅读笔记六:NSCopying协议
- linux cp命令详解
- NYOJ-01串(dp&&规律)
- CSS margin 边界叠加知识点
- 第5周项目3—时间类(1、内联成员函数)
- Chrome浏览器打印时崩溃问题