I have a List that contains a Dictionary list. The Dictionary contains the key "date" with a DateTime value, and various other keys that correspond to values of decimal numbers. I want to group by date and do the average of each decimal numbers.
I've made this before with linq but can't seem to figure it out with a dictionary.
List<object> list = new List<object>();
Dictionary<string,object> dictionary = new Dictionary<string,object>
dictionary.Add("date", date)
foreach( field in json )
{
dictionary.Add(field.Key, field.Value)
}
list.Add(dictionary);
list = list.GroupBy(m => (DateTime)m["date"], m => "not sure what to do here", (k,d) => (new object[]{k, d.Average()}).ToList()).ToList();
m["date"]
doesn't work either.
The dictionary has the following data:
- "Key" Data -"Value" 05/29/2015 05:50:06
- "Key" Processing time - "Value" 6
- "Key" Disk usage - "Value" 2
When there's no more items in the json
, the dictionary is added to the list and the process is repeated.