Action<T>泛型委托
2010-08-31 20:47
330 查看
描述:
T:
参数类型:此委托封装的方法的参数类型
arg:
参数:此委托封装的方法的参数
备注:
通过此委托,可以将方法当做参数进行传递.
其他形式:
例子:
结果:
12
11
15
6
7
8
9
10
13
封装一个方法,该方法只采用一个参数并且不返回值.
语法:public delegate void Action<T>(T arg);
T:
参数类型:此委托封装的方法的参数类型
arg:
参数:此委托封装的方法的参数
备注:
通过此委托,可以将方法当做参数进行传递.
其他形式:
public delegate void Action<T1, T2>(T1 arg1, T2 arg2); public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3); public delegate void Action<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
例子:
protected void Page_Load(object sender, EventArgs e) { List<int> list = new List<int>(); list.AddRange(new int[] { 7, 6, 10, 1, 2, 3, 4, 5, 8 }); Action<int> action = new Action<int>(AddFive); list.ForEach(action); //效果同 // Action<int> action = new Action<int>(AddFive); // list.ForEach(action); //list.ForEach(x => Response.Write((x + 5).ToString() + "<br/>")); //效果同 // Action<int> action = new Action<int>(AddFive); // list.ForEach(action); //list.ForEach(delegate(int i) //{ // HttpContext.Current.Response.Write((i + 5).ToString() + "<br/>"); //}); } public static void AddFive(int i) { HttpContext.Current.Response.Write((i + 5).ToString() + "<br/>"); }
结果:
12
11
15
6
7
8
9
10
13
相关文章推荐
- Action<T>和Func<T>泛型委托
- Func<T>与Action<T>委托泛型介绍
- Func<T>与Action<T>委托泛型介绍
- Action<T> 泛型委托
- Action<T> 泛型委托
- C#学习笔记:泛型委托Action<T>和Fun<TResult>
- Func<T>与Action<T>委托泛型介绍:转
- C#学习笔记:泛型委托Action<T>和Fun<TResult>
- Action<T>和Func<T>泛型委托
- 泛型委托 Action<T>和Func<T,TResult>
- 学习笔记之Func<T>与Action<T>委托泛型介绍
- Func<T>与Action<T>委托泛型介绍
- Action<T> 泛型委托 在跨线程访问控件委托中的应用
- 委托, 泛型委托,Func<T>和Action<T>
- C#委托Action、Action<T>、Func<T>、Predicate<T>
- Action<T> 无参数委托详解
- Action<(Of <(T>)> 委托 讲解(MSDN)
- C# Action<T> 委托
- 委托,泛型List<>[Sort (),FindAll (),BinarySearch ()] ,泛型绑定下拉框
- c# action<> func<> 这2个委托怎么用和理解