[英]how to groupby items List<keyvaluepair <string,datetime[]>> over date
I have a datatable filled by date , day ,name and type so I read from this datatable into List> using C#.net so the code is this : 我有一个由日期,日期,名称和类型填充的数据表,因此我使用C#.net从此数据表读取到List>中,因此代码如下:
dicArray = dtrd.AsEnumerable()
.Select(Row => Row["IDp"]).Distinct()
.Select(Id => new KeyValuePair<string, string[]>(
Id.ToString(),
dtrd.AsEnumerable()
.Where(Row => Row["IDp"].ToString() == Id.ToString())
.Select(Row => Row["date"].ToString()+";"+ Row["day"].ToString()+";"+Row["nobatkari"].ToString() + ";" + Row["pname"].ToString())
.ToArray()))
.ToList();
now I want to count each item over date I mean that I want to know how many rows are with the same date please help me to solve it 现在,我想对每个项目的日期进行计数。我的意思是我想知道同一日期有多少行,请帮我解决
for example: 例如:
1 **2017-02-19** 15:12:20 1 0 1 0
1 **2017-02-19** 15:12:37 1 0 1 0
1 **2017-02-19** 15:12:41 1 0 1 0 Count:3
1 **2017-02-20** 15:14:10 1 2 1 0
1 **2017-02-20** 16:38:14 1 2 1 0
3 **2017-02-20** 16:38:19 1 2 1 0 Count:3
3 **2017-02-21** 16:39:09 1 0 1 0
3 **2017-02-21** 17:25:06 1 0 1 0
2 **2017-02-21** 18:28:50 1 0 1 0 Count:3
2 **2017-02-22** 18:29:04 1 0 1 0 Count:1
2 **2017-02-23** 18:29:17 1 0 1 0
3 **2017-02-23** 18:30:45 1 0 1 0 Count:2
2 **2017-02-24** 18:31:32 1 0 1 0
2 **2017-02-24** 18:31:47 1 0 1 0 Count:2
2 **2017-02-25** 18:32:18 1 4 1 0 Count:1
Of course I want date section not time include 我当然要日期部分不包括时间
var res = yourList.GroupBy(x => x.date.Date).Select(x=> new { date = x.Key, count = x.Count() });
这将创建一个包含日期和每个日期的元素计数的新列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.