简单使用的例子
{ List<int> list = new List<int>(){0,1,2,23,214}; var rst= list.Where(item => item > 5); var rst2 = list.Where<int>(new Func<int, bool>(item => { return item > 5; })); var rst3 = from item in list where item > 5 select item; foreach (var item in rst) { Console.WriteLine(item.ToString()); } foreach (var item in rst2) { Console.WriteLine(item.ToString()); } foreach (var item in rst3) { Console.WriteLine(item.ToString()); }
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
是框架LINQ的定义,没有Where()方法但是可以用list.Where(item => item > 5)调用,可能会自动转换类型