public static void Play() { var egents = SimpleAgent.Create(); var districts = egents.GroupBy(x => x.District).Select(x => new SimpleAgent { District = x.Key, TotalIncome = x.Sum(a => a.TotalIncome) }); foreach (var di in districts) { Console.WriteLine($"la provincia {di.District} ha come totale {di.TotalIncome} tollari di guadagno"); } var enonymouSdistricts = egents.GroupBy(x => x.District).Select(x => new { District = x.Key, TotalIncome = x.Sum(a => a.TotalIncome) }); foreach (var di in districts) { Console.WriteLine($"la provincia {di.District} ha come totale {di.TotalIncome} tollari di guadagno"); } }
public static void Play() { var agents = SimpleAgent.Create(); Console.WriteLine("Select dopo aver creato una classe DistrictIncome per lo scopo"); var districtIncomes = agents .GroupBy(x => x.District) .Select(x => new DistrictIncome { District = x.Key, TotalIncome = x.Sum(a => a.TotalIncome) }); foreach (var di in districtIncomes) { Console.WriteLine($"La provincia {di.District} ha raggiunto {di.TotalIncome} di guadagno"); } Console.WriteLine(); var anonymousDistrictIncomes = agents .GroupBy(x => x.District) .Select(x => new { District = x.Key, TotalIncome = x.Sum(a => a.TotalIncome) }); foreach (var di in anonymousDistrictIncomes) { Console.WriteLine($"La provincia {di.District.ToUpper()} ha raggiunto {di.TotalIncome} di guadagno"); } }