asp.net 委托与拉姆达表达示例子
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Data;
using Utility;
using System.Web.Services;
using SJLERP.Models.BLL;
using System.Net;
using System.Xml;
namespace SJLERP
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var list = new 委托<bool>();
list._list = new List<bool>();
list._list.Add(true);
list._list.Add(false);
list._list.Add(true);
///实现委托 asp.net
list.FuncAllLen += Temp;
Response.Write(list.AllLen().ToString());
var list2 = new 拉姆达<bool>();
list2._list = new List<bool>();
list2._list.Add(true);
list2._list.Add(false);
list2._list.Add(true);
int intRef = list2.AllLen(
PList =>
{
int i = 0;
foreach (var item in PList)
{
if (item) i++;
}
return i;
});
}
public class 拉姆达<T>
{
public Func<T, int> FuncAllLen { get; set; }
public List<T> _list { get; set; }
//其实我把上面的委托定义放到函数里面当参数了....
public int AllLen(Func<List<T>, int> FuncAllLen)
{
if (FuncAllLen != null)
{
return FuncAllLen(_list);
}
return 0;
}
}
public class 委托<T>
{
public delegate int delegateAllLen<T>(List<T> list);
public List<T> _list { get; set; }
//www.52mvc.com写一个委托,谁愿意做什么操作就自己写去,哥不管了!
public delegateAllLen<T> Func