LINQ 学习路程 -- 查询操作 Aggregate】的更多相关文章

聚合操作执行数学的运算,如平均数.合计.总数.最大值.最小值 Method Description Aggregate 在集合上执行自定义聚集操作 Average 求平均数 Count 求集合的总数 LongCount 求集合的总数 Max 最大值 Min 最小值 Sum 总数 public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TS…
表达式树就像是树形的数据结构,表达式树中的每一个节点都是表达式, 表达式树可以表示一个数学公式如:x<y.x.<.y都是一个表达式,并构成树形的数据结构 表达式树使lambda表达式的结构变得透明清楚, Expression<Func<Student, && s.age < ; 编译器将上面的表达式翻译成下面的表达式树 Expression.Lambda<Func<Student, bool>>( Expression.AndAlso(…
Sorting Operator Description OrderBy 通过给定的字段进行升序 降序 排序 OrderByDescending 通过给定字段进行降序排序,仅在方法查询中使用 ThenBy 第二级升序排序,仅在方法查询中使用 ThenByDescending 第二级降序排序,仅在方法查询中使用 Reverse 反转集合,仅在方法查询中使用 IList<Student> studentList = new List<Student>() { , StudentName…
延迟执行是指一个表达式的值延迟获取,知道它的值真正用到. 当你用foreach循环时,表达式才真正的执行. 延迟执行有个最重要的好处:它总是给你最新的数据 实现延迟运行 你可以使用yield关键字实现延迟加载 public static class EnumerableExtensionMethods { public static IEnumerable<Student> GetTeenAgerStudents(this IEnumerable<Student> source)…
Join操作是将两个集合联合 Joining Operators Usage Join 将两个序列连接并返回结果集 GroupJoin 根据key将两个序列连接返回,像是SQL中的Left Join Join操作两个集合,inner collection 和 outer collection 它返回一个集合(包含两个集合根据特定条件结合的所有元素),和SQL中的inner join一样 public static IEnumerable<TResult> Join<TOuter, TIn…
1.where Filtering Operators Description Where Returns values from the collection based on a predicate function OfType Returns values from the collection based on a specified type. However, it will depend on their ability to cast to a specified type.…
Grouping Operators Description GroupBy GroupBy操作返回根据一些键值进行分组,每组代表IGrouping<TKey,TElement>对象 ToLookup ToLookup is the same as GroupBy; the only difference is the execution of GroupBy is deferred whereas ToLookup execution is immediate. IList<Stude…
IList<Student> studentList = new List<Student>() { , StudentName = } , , StudentName = } , , StudentName = } , , StudentName = } , , StudentName = } }; var lowercaseStudentNames = from s in studentList where s.StudentName.ToLower().StartsWith(…
IList<Student> studentList = new List<Student>() { , StudentName = "John" }, , StudentName = "Moin" }, , StudentName = "Bill" }, , StudentName = "Ram" }, , StudentName = "Ron" } }; var selectRe…
OfType操作根据集合中的元素是否是给定的类型进行筛选 IList mixedList = new ArrayList(); mixedList.Add(); mixedList.Add("One"); mixedList.Add("Two"); mixedList.Add(); mixedList.Add(, StudentName = "Bill" }); var stringResult = from s in mixedList.OfT…