Here are two C# classes…
public class Address
{
public string Country;
public string City;
}
public class Traveller
{
public string Name;
public List<Address> TravelRoute;
}
… and a list of data (filled somewhere) …
List<Traveller> Travellers;
… and then this LINQ query:
var result = from t in Travellers
where t.TravelRoute.Any(a => a.Country == "F")
select t;
foreach (var t in result)
System.Console.WriteLine(t.Name);
I do not understand the query: What means the “Any” function and what does the “=>” operator do?
Can someone explain me what’s going on in this code? Thanks!
The line
would translate to something like this if it was a separated LINQ statement:
The any means it : Any.
In other word, it will return true if ANY of the objects in travelRoute has its Country property to “F”
Hope that helps