I have those classes:
public class Flight
{
public string FlightNum { get; set; }
public List<Pax> Pax { get; set; }
}
public class Pax
{
public string PaxName { get; set; }
public string PaxSurName { get; set; }
}
I want to filter flight so that it will only contain flights whose passenger’s name is a certain string
I tried:
var paxList = flights.Where(f => f.Pax.Where(p => p.PaxName == "d"));
The above code didn’t work…
e.g: I want to this in a SINGLE Lambda expression
Whereneeds a function that returns aboolean.The nested expression
f.Pax.Any(p => p.PaxName == "d")will return true if anypmatches the criterion thatPaxNameis exactly"d".And hence the resulting list will be of flights (not passengers) which contain any passenger meeting that criterion. I mention this because
paxListis potentially not a good variable name.