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();
  • 相关阅读:
    BZOJ 1007 HNOI2008 水平可见的直线
    BZOJ 3155 Preprefix sum
    BZOJ 1036 ZJOI2008 树的统计
    BZOJ 1096 ZJOI2007 仓库建设
    BZOJ 1012 JSOI2008 最大数maxnumber
    BZOJ 1001 狼抓兔子
    BZOJ 1046 HAOI 上升序列
    [POI2015]PUS
    [NOI2011]道路修建
    POI 2015 KIN
  • 原文地址:https://www.cnblogs.com/pnljs/p/2933672.html
Copyright © 2011-2022 走看看