Lambda expressions , Action , Func and Predicate
2016-04-30 21:05
295 查看
http://www.tutorialsteacher.com/csharp/csharp-action-delegate
lambda 表达式
Action,func
lambda表达式是什么,其有什么优点,不使用lambda
其的目的:简化代码。
在JAVA当中一般是使用接口来实现
Action is also a delegate type defined in the System namespace. An Action type delegate is the same as Func delegate except that the Action delegate doesn't return a value. In other words, an Action delegate can be used with a method that has a void return type.
Action is also a delegate type 其也可以推导出来两个结论。
1. action 是一个type,类似于int, 那就可以定义变量,其定义一个什么样类型的变量,其变量的含义是什么。就需要下面一个推论。
2. action 是一个delegate type,其就是一个delegate,那就是一个函数指针,用于方法之间的调用。
其包含有delegate的所有特点,那其又有什么不同。
3. 有了delegate那又要有Action,使用action其的目的是为了更加简化。
delegate 其需要先定义且要定义方法名
Makes code short.
Compatible type throughout the application.
【action 其使用的场景】
1. 在框架当中的线程之间使用
this._readThread = ThreadEx.ThreadCall(new Action(this.ReadThread));
public static System.Threading.Thread ThreadCall(System.Action action)
{
return ThreadEx.ThreadCall(action, null);
}
public static System.Threading.Thread ThreadCall(System.Action action, string name)
{
return ThreadEx.Call(action, name);
}
public static System.Threading.Thread Call(System.Action action, string name)
{
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(action.Invoke));
if (name != null)
{
thread.Name = name;
}
thread.Start();
return thread;
}
lambda 表达式
Action,func
lambda表达式是什么,其有什么优点,不使用lambda
其的目的:简化代码。
在JAVA当中一般是使用接口来实现
Action is also a delegate type defined in the System namespace. An Action type delegate is the same as Func delegate except that the Action delegate doesn't return a value. In other words, an Action delegate can be used with a method that has a void return type.
Action is also a delegate type 其也可以推导出来两个结论。
1. action 是一个type,类似于int, 那就可以定义变量,其定义一个什么样类型的变量,其变量的含义是什么。就需要下面一个推论。
2. action 是一个delegate type,其就是一个delegate,那就是一个函数指针,用于方法之间的调用。
其包含有delegate的所有特点,那其又有什么不同。
3. 有了delegate那又要有Action,使用action其的目的是为了更加简化。
public delegate void Print(int val);
delegate 其需要先定义且要定义方法名
Action<int> 其就直接定义形参的类型且不要返回值。[/code]
Advantages of Action and Func delegates:
Easy and quick to define delegates.Makes code short.
Compatible type throughout the application.
【action 其使用的场景】
1. 在框架当中的线程之间使用
this._readThread = ThreadEx.ThreadCall(new Action(this.ReadThread));
public static System.Threading.Thread ThreadCall(System.Action action)
{
return ThreadEx.ThreadCall(action, null);
}
public static System.Threading.Thread ThreadCall(System.Action action, string name)
{
return ThreadEx.Call(action, name);
}
public static System.Threading.Thread Call(System.Action action, string name)
{
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(action.Invoke));
if (name != null)
{
thread.Name = name;
}
thread.Start();
return thread;
}
相关文章推荐
- 禁忌搜索基础知识
- Java 之 线程和进程
- Lightoj--1338--Hidden Secret!(模拟)
- Axure制作ipad原型
- 10个值得深思的 PHP 面试问题
- Boost.log的应用
- bootstrap表单验证插件 经验记录 与RSA加密事件配合修改
- leetcode151: symmetric tree
- 1048. 数字加密(20)
- C经典 快速实现加减乘除
- 第二次打字测试
- jquery操作DOM元素的复习
- PHP限制网页只能在微信内置浏览器中查看并显示
- Java循环练习:百鸡问题
- 时隔三年,重回代码之路
- 构建之法04
- servlet、jsp跳转(传值)总结及URL传参数
- linux内存源码分析 - 内存回收(lru链表)
- OSI七层模型与TCP/IP模型
- Unity3D 关于运动模型