zoukankan      html  css  js  c++  java
  • 对DataTable的DataRow做group

       1:  public void DataSetLinq41()
       2:  {
       3:      var words4 = testDS.Tables["Words4"].AsEnumerable();
       5:      var wordGroups =
       6:          from w in words4
       7:          group w by w.Field<string>("word")[0] into g
       8:          select new { FirstLetter = g.Key, Words = g };
      10:      foreach (var g in wordGroups)
      11:      {
      12:          Console.WriteLine("Words that start with the letter '{0}':", g.FirstLetter);
      13:          foreach (var w in g.Words)
      14:          {
      15:              Console.WriteLine(w.Field<string>("word"));
      16:          }
      17:      }
      18:      Console.ReadLine();
      19:  }
      20:   
      21:   
      22:  private static DataTable CreateWords4Table()
      23:  {
      24:      string[] words = { "blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese" };
      25:      DataTable table = new DataTable("Words4");
      26:      table.Columns.Add("word", typeof(string));
      27:   
      28:      foreach (string word in words)
      29:      {
      30:          table.Rows.Add(new object[] { word });
      31:      }
      32:      return table;
      33:  }
      34:   
      35:  DataSetLinq41();
  • 相关阅读:
    Hlg 1740 DP求路径且按最小字典序输出.cpp
    Uestc 1720 【容斥原理】.cpp
    Uva 10112 【简单的计算几何】.cpp
    Vijos 1071 【DP之记录路径】
    Hlg 1665 【KMP】.cpp
    cf 226b 唯美思维题~.cpp
    Hlg 1049 【广搜+康拓展开】.cpp
    Hlg 1067 【状态压缩DP】.cpp
    Pythoner.CN: 中小企业IT不可错过的十大虚拟机软件 | Pythoner.CN
    OpenStack Hacker养成指南 | UnitedStack Inc.
  • 原文地址:https://www.cnblogs.com/pnljs/p/2933672.html
Copyright © 2011-2022 走看看