CSharp · Console
using System;
using System.Data;
using System.Data.DataSetExtensions;
using System.Linq;
using System.Xml;
public class Program
{
public static void Main()
{
DataTable table = GetTable();
var groupedData = from b in table.AsEnumerable()
group b by b.Field<int>("Number") into g
select new
{
Number= g.Key,
Count = g.Count()
};
groupedData.ToList().ForEach(i => Console.Write("{0}\t", i));
}
static DataTable GetTable()
{
// Here we create a DataTable with two columns.
DataTable table = new DataTable();
table.Columns.Add("Title", typeof(string));
table.Columns.Add("Number", typeof(int));
// Here we add five DataRows.
table.Rows.Add("Заголовок 1",1);
table.Rows.Add("Заголовок 2",15);
table.Rows.Add("Заголовок 4",15);
table.Rows.Add("Заголовок 3",15);
table.Rows.Add("Заголовок 5",15);
return table;
}
}