I have the following classes:
public class Line
{
public List<Trip> Trips;
}
public class Trip
{
public TimeSpan Departure { get; set; }
public TimeSpan Arrival { get; set; }
}
and an object List<Line> lines.
Using Linq I'm trying to find a list of all times in trips, regardless of whether it's departure time or arrival time, possibly without duplicates.
So for example:
DEPARTURE | ARRIVAL
05:11 | 12:32
08:00 | 11:00
12:32 | 14:00
should return:
05:11
12:32
08:00
11:00
14:00
I tried something like this:
var l = lines
.SelectMany(t => t.Trips)
.Select(x => x.Departure).Concat(x => x.Arrival);
or
var l = lines
.SelectMany(t => t.Trips)
.SelectMany(x => new { x.Departure, x.Arrival });
but they didn't work.
I found this answer but I cannot adapt it to my situation.