Skip to content

Incorrect Output #43760

@mthanson8333

Description

@mthanson8333

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

https://github.com/dotnet/docs/blob/main/docs/csharp/linq/get-started/query-expression-basics.md

Document Version Independent Id

4fa6e86d-a790-6933-e0ee-a090e3133f0f

Article author

@BillWagner

Metadata

  • ID: d9fdf663-0533-1971-d9e0-245f1cdc69d7
  • Service: dotnet-csharp
  • Sub-service: csharp-linq

Related Issues


Associated WorkItem - 350767

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.csharp-linq/subsvcdotnet-csharp/svcin-prThis issue will be closed (fixed) by an active pull request.okr-freshnessOKR: Freshness of contentokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions