public static List <string> GetProvincesGroupBy(PersonList persons) { var result = new List <string>(); foreach (var item in persons.GroupBy(x => x.Province)) { result.Add(item.Key); } return(result); }
public static List <PersonsInProvince> GetProvincesPersons(PersonList persons) { var result = new List <PersonsInProvince>(); foreach (var item in persons.GroupBy(x => x.Province)) { var data = new PersonsInProvince { ProvinceName = item.Key, Amount = item.Count() }; result.Add(data); } return(result); }