public void AddPopulations(List <Population> populations) { foreach (Population population in populations) { Population popMatch = Populations.FirstOrDefault(pop => pop.Race.NamePlural.Equals(population.Race.NamePlural, StringComparison.InvariantCultureIgnoreCase)); if (popMatch != null) { popMatch.Count += population.Count; } else { Populations.Add(new Population(population.Race, population.Count)); } } Populations = Populations.OrderByDescending(pop => pop.Count).ToList(); Parent?.AddPopulations(populations); }
public void AddPopulations(List <Population> populations) { foreach (Population population in populations) { Population popMatch = Populations.FirstOrDefault(pop => pop.Race == population.Race); if (popMatch != null) { popMatch.Count += population.Count; } else { Populations.Add(new Population(population.Race, population.Count)); } } Populations = Populations.OrderByDescending(pop => pop.Count).ToList(); Parent?.AddPopulations(populations); }