简体   繁体   English

如何分组项目列表 <keyvaluepair <string,datetime[]> &gt;过期

[英]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.

相关问题 如何分组列表 <KeyValuePair<string, string[]> &gt;在c#.net中 - how to groupby List<KeyValuePair<string, string[]>> in c#.net 如何通过KeyValuePair的特定列分组<string, DataRow> - How to GroupBy a specific column for a KeyValuePair<string, DataRow> 检查项目是否不在键值对列表中 - check if items are not in a keyvaluepair list 如何转换清单 <KeyValuePair<string, decimal> &gt;列表=新列表 <KeyValuePair<string, decimal> &gt;(); 到DataTable? - How to convert List<KeyValuePair<string, decimal>> list = new List<KeyValuePair<string, decimal>>( ); to DataTable? 如何对KeyValuePair的ComboBox.Items集合进行排序 <string,string> 按价值? - How to sort a ComboBox.Items collection of KeyValuePair<string,string> by Value? 如何正确使用列表上的LINQ查询 <KeyValuePair<string, string> 创建字典 <KeyValuePair<string, string> ,int&gt;? - How to properly use LINQ Query on List<KeyValuePair<string, string> to create Dictionary<KeyValuePair<string, string>, int>? 如何缩短列表 <List<KeyValuePair<string, string> &gt;&gt;? - How can I shorten List<List<KeyValuePair<string, string>>>? Linq(按组和求和)在列表中 <List<string> &gt; - Linq (GroupBy and Sum) over List<List<string>> 排序列表 <keyValuePair<string,string> &gt; - Sort list<keyValuePair<string,string>> 如何deserialzie KeyValuePair列表 - How to deserialzie List of KeyValuePair
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM