zoukankan      html  css  js  c++  java
  • Linq分组操作之GroupBy,GroupJoin扩展方法源码分析

    Linq分组操作之GroupBy,GroupJoin扩展方法源码分析

    一. GroupBy 

      解释: 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。

    查询表达式:

    var list = new List<object>() { 20, 30, 24 };查询表达式:

     var query = from n in list
                            group n by n
                          into grp
                            select new
                            {
                                MyKey = grp.Key,
                                MyValue = grp.Count()
                            };
      //如下: 会以Key 为分组,与sql一样
                var wordList = new List<word>()
                {
                    new word { Key="dragon", length=1, str=""},
                    new word { Key="dragon", length=21, str=""},
                    new word { Key="joc", length=31, str=""}
    
                };
                var keyCount = wordList.GroupBy(i=>i.Key).ToArray();

     二. GroupJoin

      解释:基于键相等对两个序列的元素进行关联并对结果进行分组。使用默认的相等比较器对键进行比较。

         也就是关联后的分组

            var query2 = from n in wordList
                             join m in word2List
                             on n.Key equals m.Key
                             into grp
                             select new
                             {
                                 Key = n.Key,
                                 Value = grp.Count()
                             };
  • 相关阅读:
    好用的QT连接
    c指针点滴-指针与类型
    c指针点滴5-指针变量计算
    c指针点滴4-指针的值
    c指针点滴三(指针运算)
    c语言指针点滴1
    c指针点滴2之比大小
    c指针点滴1
    linux安装redis
    支付宝支付接口流程
  • 原文地址:https://www.cnblogs.com/dragon-L/p/6492816.html
Copyright © 2011-2022 走看看