group by average on a list of objects in C# -


i have list of objects object looks below

public class sample {     public datetime _dt;     public decimal _d;     public decimal_value; } 

i want list grouped year , month of date , _d values _value averaged.

so if month jan, list has

one set of 31 values _d =1,  1 set of 31 values _d =5 

result list of sample have 2 values

1/1/2016 ,_d = 1 , average of _value 1/1/2016 ,_d = 5 , average of _value 

initially have redefine sample class.

public class sample {     public datetime _dt   { get; set; }     public decimal _d     { get; set; }     public decimal _value { get; set; } } 

if have list of sample objects called samples, want:

var results = samples.groupby(sample => { year = _dt.year, month = _dt.month dvalue = _d})                      .select(gr => new {                          year = gr.key.year,                          month = gr.key.month,                          dvalue = gr.key.dvalue,                          averagevalue = gr.select(item => item.value).average()                      }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -