Calculate average in each group
- by Gokul
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