Https://www.cnblogs.com/johnblogs/p/6006867.html
DataTable ds = new DataTable ();
1.LAMDA expression (recommended)
var result = ds. AsEnumerable (). GroupBy (s = = New{year = S.field<int> ("year"), month = s.field<int> ("month"), day = S.field<int> (" Day ")});
2. Linq syntax The final compiler converts it to LAMDA expression
var result = from S in DS. Tables[0]. AsEnumerable ()
Group S by new {year = S.field<int> (' year '), month = s.field<int> ("month"), day = s.field<int> ("Day")} Into temp
Select temp;
DataTable using the GroupBy method needs to be aware that result is of type igrouping<int,datarow>
foreach (var thisgroup in result)
{
foreach (var row in Thisgroup)
{
Traverse all the row currently in this group
}
}
Statistics do not repeat the number, no test is not known whether the DT can be used. Defaultview.totable (True, new string[1] {"UserName"}). Rows.Count; Http://www.xuebuyuan.com/1990057.htmlusing (DataTable dt = ds. Tables[0])
{
Three variables record the total number of records, the number of users that are not duplicated, the total amount of all users
int Rowscount, Distinctuserrowscount, Allusermoney;
Rowscount = dt. Rows.Count;
Distinctuserrowscount = dt. Defaultview.totable (True, new string[1] {"UserName"}). Rows.Count;
Allusermoney = Convert.todecimal (Dt.compute ("sum (Usermoney)", ""));
}
c#datatable LAMDA Expressions and LINQ statements using the GroupBy method