zoukankan      html  css  js  c++  java
  • LINQ语法之into

    可以使用 into 上下文关键字创建一个临时标识符,以便将 group、join 或 select 子句的结果存储到新的标识符中。此标识符本身可以是附加查询命令的生成器。在 group 或 select 子句中使用新标识符的用法有时称为“延续”。

    下面的示例演示使用 into 关键字来启用临时标识符 fruitGroup,该标识符具有推断类型 IGrouping。通过使用该标识符,可以对每个组调用 Count 方法,并且仅选择那些包含两个或更多个单词的组。

     
    class IntoSample1
    {
        static void Main()
        {
     
            // Create a data source.
            string[] words = { "apples", "blueberries", "oranges", "bananas", "apricots"};
     
            // Create the query.
            var wordGroups1 =
                from w in words
                group w by w[0] into fruitGroup
                where fruitGroup.Count() >= 2
                select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };
     
            // Execute the query. Note that we only iterate over the groups, 
            // not the items in each group
            foreach (var item in wordGroups1)
            {
                Console.WriteLine(" {0} has {1} elements.", item.FirstLetter, item.Words);
            }
     
            // Keep the console window open in debug mode
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
     
    /* Output:
       a has 2 elements.
       b has 2 elements.
    */
     

    仅当希望对每个组执行附加查询操作时,才需要在 group 子句中使用 into。

  • 相关阅读:
    费用流
    平面最近点对
    纸牌均分问题
    cdq分治模板
    费解的开关
    斐波那契和排列组合性质
    主席树
    Springboot使用EasyExcel(仅限自己收藏)
    vue项目中h5移动端中通过flex布局实现首尾固定,中间滚动(借鉴)
    vue路由参数的获取、添加和替换
  • 原文地址:https://www.cnblogs.com/poissonnotes/p/1758464.html
Copyright © 2011-2022 走看看