c# - How to get average of list within lists using linq? -


i creating method list of business objects tie highest average rating. method starts list of businesses. each business contains list of review objects contain rating (int).

to illustrate:

list<review> reviews = curtbusiness.getreviews(); reviews[1].getrating(); 

using loop find easily, unfortunately required use linq, have no skills at.

can me make linq statement query or similar query?

update:

i think may have stumbled solution

 double average = busincat.max(b=> b.getreviews().average(r => r.getrateing()));         return busincat.where(b => b.getreviews().average(r => r.getrateing()) == average).tolist(); 

if above code correct first finds max average of ratings in first line.

then in second line returns list of of businesses have average rating. can confirm linq expressions doing?

i don't quite understand you're looking here, i'll take guess.

you have review object, has method int getrating(), have list of these objects , want find average of ratings

something trick

// reviews var reviews = curtbusiness.getreviews();  // average of getrating() results of reviews var average = reviews.average(r => r.getrating()); 

is you're looking for? can offer further explanation, i'd sure you're after.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -