Question

The MSDN article "Order Preservation in PLINQ" states:

The following example overrides the default behavior by using the AsOrdered operator on the source sequence. This ensures that the Take method returns the first 10 cities in the source sequence that meet the condition

var orderedCities = (from city in cities.AsParallel().AsOrdered()
                     where city.Population > 10000
                     select city)
                       .Take(1000);

Is it possible to return more (or less) than 10 first items ordered in PLINQ query and how?

Was it helpful?

Solution

Take(1000) will try to return the first 1000 elements in cities that meet the conditions defined in where city.Population > 10000.

There is a possibility that you will receive less than 1000 elements, when there aren't enough elements that meet your requirements (or you never had enough elements in your collection to begin with).
However, there is no way you'll get more than 1000 elements, unless you specifically ask for more elements, e.g. Take(1001) which will try to return 1001 elements.

For more information on Take, visit MSDN

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top