Calculate average in each group

Posted by Gokul on Stack Overflow See other posts from Stack Overflow or by Gokul
Published on 2010-05-20T10:59:51Z Indexed on 2010/05/20 11:10 UTC
Read the original article Hit count: 214

Filed under:
|

I am using the following class

class Country
{
   int CountryID {get; set;}
   List<City> city {get; set;}
}

class City
{
   int CountryID {get; set; }
   string city {get; set;}  
   int sqkm {get; set;}
}

Here's is some sample data for Country and City

Country

US
UK
Canada

City

CityC
CityF
CityA
CityB
CityG
CityD
CityE

I am populating using

List<Country> countries = new List<Country> { new Country() { CountryID = "US", city = new List<City> { new City() {CountryID = "US", City  ="CityF", sqkm = 2803 }, and so on

Question 1: I want to use LINQ to find avg sq. km of land per country

Eg:

Canada - 2459
UK - 3243
US - 3564

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#