这是p哥写的一个小demo,今天无意中看到了。但是在这小弟有一句没看懂
http://topic.csdn.net/u/20100724/18/b5927dbb-bb6b-40e3-858c-4063d2479efc.htmlif (g.下级部门.Count > 0)
g.下级部门.ForEach(x => { BindDepartment(treenode.ChildNodes, x); });我在msdn查过List<T>.ForEach(),看不懂得是ForEach()这里面的参数为什么会是这样的,能否详细说明下!
http://topic.csdn.net/u/20100724/18/b5927dbb-bb6b-40e3-858c-4063d2479efc.htmlif (g.下级部门.Count > 0)
g.下级部门.ForEach(x => { BindDepartment(treenode.ChildNodes, x); });我在msdn查过List<T>.ForEach(),看不懂得是ForEach()这里面的参数为什么会是这样的,能否详细说明下!
Action<T> 是一个委托,原型是
private bool IsMath(T t) {
return true;//此逻辑判断,返回结果
}
他这用的是Lambda 表达式 方便多了~~~[align=center]********************************************************
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
[/align]
//通过这个DEMO 我想你就明白了
void Main()
{
List<int>list=new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.ForEach(l=>Console.WriteLine(l));
/*
1
2
3
4*/
}
ForEach的委托原型Action<T>是:
private void EachItem(T) {
//……
}
BindDepartment(treenode.ChildNodes, x); 这个方法你要看一下,基本就ok了