-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Type of issue
Other (describe below)
Description
The second example under "Query variable" produces different results.
`City[] cities = [
new City("Tokyo", 37_833_000),
new City("Delhi", 30_290_000),
new City("Shanghai", 27_110_000),
new City("São Paulo", 22_043_000)
];
//Query syntax
IEnumerable queryMajorCities =
from city in cities
where city.Population > 100000
select city;
// Execute the query to produce the results
foreach (City city in queryMajorCities)
{
Console.WriteLine(city);
}
// Output:
// City { Population = 120000 }
// City { Population = 112000 }
// City { Population = 150340 }
// Method-based syntax
IEnumerable queryMajorCities2 = cities.Where(c => c.Population > 100000);`
Actual output is:
City { Name = Tokyo, Population = 37833000 } City { Name = Delhi, Population = 30290000 } City { Name = Shanghai, Population = 27110000 } City { Name = São Paulo, Population = 22043000 }
Recommend updated the where in queryMajorCities.
[Enter feedback here]
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/linq/get-started/query-expression-basics
Content source URL
Document Version Independent Id
4fa6e86d-a790-6933-e0ee-a090e3133f0f
Article author
Metadata
- ID: d9fdf663-0533-1971-d9e0-245f1cdc69d7
- Service: dotnet-csharp
- Sub-service: csharp-linq