private static void ElementOperators() { Console.WriteLine("Elements"); List <F1Team> teams = F1Data.GetTeams(); F1Team team = teams.ElementAt(0); team = teams.First(t => t.TeamName.Contains("a")); team = teams.Last(); team = teams.SingleOrDefault(t => t.Pilots.Length == 3); }
public static void Grouping() { Console.WriteLine("---- grouping"); List <F1Team> teams = F1Data.GetTeams(); var query = from team in teams from pilot in team.Pilots group pilot by team; foreach (var group in query) { Console.WriteLine(group.Key); foreach (var pilot in group) { Console.WriteLine(" - {0} {1}", pilot.FirstName, pilot.LastName); } } foreach (IGrouping <F1Team, Pilot> group in query) { F1Team team = group.Key; Console.WriteLine(team); foreach (Pilot pilot in group) { Console.WriteLine(" - {0} {1}", pilot.FirstName, pilot.LastName); } } var query2 = from team in teams from pilot in team.Pilots group pilot by team into t select new { t.Key, t }; foreach (var pilot in query2) { Console.WriteLine(pilot.Key); } }