The text file containing cars' arrival and departure time will upload stuff from the parking lot.Text will be like this:10:10, 11:1010:30, 12:40 10:25, 11:1011:10, 12:20I created a ParkedCar class:public class ParkerCar{    public DateTime ArrivalTime { get; set; }    public DateTime DepartureTime { get; set; }}The method that parses the text file, fills into List<ParkedCar>, and sorts them by the cars' arrival time:public class ParkingLotRepository{    public List<ParkedCar> getParkedCars()    {        List<ParkedCar> parkedCars = new List<ParkedCar>();        foreach (string line in File.ReadLines(path))        {            string[] times = line.Split(',');            bool isValid = true;            DateTime dtStart;            if (!DateTime.TryParseExact(times[0].Trim(), HH:mm,                CultureInfo.InvariantCulture,                DateTimeStyles.NoCurrentDateDefault, out dtStart))                isValid = false;            DateTime dtEnd;            if (!DateTime.TryParseExact(times[1].Trim(), HH:mm,                CultureInfo.InvariantCulture,                DateTimeStyles.NoCurrentDateDefault, out dtEnd))                isValid = false;            if (isValid)            {                parkedCars.Add(new ParkedCar                {                    ArrivalTime = dtStart,                    DepartureTime = dtEnd                });            }        }        parkedCars = parkedCars            .OrderBy(c => c.ArrivalTime)            .ThenBy(c => c.DepartureTime)            .ToList();        return parkedCars;    }}I wrote the method shown below to find the busiest time-frame and how many cars were in the parking lot. I'm not sure if this is an effective way to do that:public static ParkTimeframe getPickTimeframe(List<ParkedCar> cars){    List<ParkTimeframe> timeFrames = new List<ParkTimeframe>();    DateTime dtStart = cars.First().arrivalTime;    DateTime dtEnd = cars.First().leavingTime;    int count = 0;    foreach (ParkedCar car in cars)    {        if (car.arrivalTime <= dtEnd && car.arrivalTime >= dtStart)        {            count++;        }        else        {            timeFrames.Add(new ParkTimeframe            {                startTime = dtStart,                endTime = dtEnd,                countCars = count            });            dtStart = car.arrivalTime;            dtEnd = car.leavingTime;            count = 0;        }    }    int maxCountCar = timeFrames.Max(x => x.countCars);    return timeFrames.First(x => x.countCars == maxCountCar);}public class ParkedCar{    public DateTime arrivalTime { get; set; }    public DateTime leavingTime { get; set; }}Also, is there a better way to do that using LINQ?
Finding the busiest time-frame in a parking lot
c#;performance;linq;interval