I have a list Allflights of object type FLightInfo.
If an object from the list has the same flightNumber and takeofftime. I want to consolidate those entries and add their user count
Example: This is my list:
- FlightNumber 123 Takeoff 12:00 Users 5
- FlightNumber 256 Takeoff 3:00 Users 6
- FlightNumber 123 Takeoff 12:00 Users 8
- FlightNumber 651 Takeoff 5:00 Users 3
I want the output to be like:
FlightNumber 123 Takeoff 12:00 Users 13
FlightNumber 256 Takeoff 3:00 Users 6
FlightNumber 651 Takeoff 5:00 Users 3
My source code:
struct FlightInfo
{
public string FlightNumber { get; set; }
public string Takeoff_time { get; set; }
public string Landing_time { get; set; }
public int UserCount { get; set; }
}
static List<FlightInfo> allFlights = new List<FlightInfo>();
//I read several files using multi-threading and create a FlightInfo object
//and add it to the allFlights list
allFlights.Add(buildFlight(FlightNumber, Origination, Destination, Takeoff_time, Landing_time, UserCount);
//This is what I need to do
//if FlightNumber && testTakeOff object attributes are the same
// I want to consolidate those entries and add the UserCount from those entries