using System; using System.Collections.Generic; var sessions = new[] { new Session("Blue", new[] { 70, 71, 72 }), new Session("Gold", new[] { 70, 70, 71, 71 }), new Session("Green", new[] { 72, 72 }), }; Console.WriteLine("Practice lap times"); foreach (Session session in sessions) { PrintSummary(session); } static void PrintSummary(Session session) { Console.WriteLine(); Console.WriteLine($"Driver: {session.Driver}"); Console.WriteLine($"Laps: {string.Join(", ", session.LapSeconds)}"); Console.WriteLine($"Best lap: {FindFastestLap(session.LapSeconds)} s"); Console.WriteLine(FormattableString.Invariant( $"Average: {CalculateAverageLap(session.LapSeconds):0.00} s")); } static int FindFastestLap(IReadOnlyList lapSeconds) { int fastest = lapSeconds[0]; for (int index = 1; index < lapSeconds.Count; index++) { fastest = Math.Min(fastest, lapSeconds[index]); } return fastest; } static double CalculateAverageLap(IReadOnlyList lapSeconds) { int totalSeconds = 0; foreach (int seconds in lapSeconds) { totalSeconds += seconds; } return totalSeconds / lapSeconds.Count; } record Session(string Driver, IReadOnlyList LapSeconds); // Есть ли баги в этом коде?