
























简单的 Where,实现可能如下:
public static List<T> Where (this List<T> list,委托 delegate)
{
List<T> tmpList = new List<T> ();
foreach( T p in list){
if(delegate(p)){
tmpList.add(p);
}
}
return tmpList;
}
List<Person> persons = new List<Person> {"sds","sdsd"};
下面分别使用
Lambda表达式和匿名方法 static void Main(string[] args)
{
var ints = new int[] { 1, 2, 3, 4, 5, 6 };
IEnumerable<int> q = from i in ints select i;
foreach(............)
}
此时的q并未返回查询的结果,而是返回一个IEnumerable<int>,以使foreach可以工作;
这里有准确的说法:
http://blog.joycode.com/scottgu/archive/2007/04/09/100744.aspx
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。