0

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?

Community
  • 1
  • 1
Fulproof
  • 4,466
  • 6
  • 30
  • 50
  • 1
    More ***AND*** less? Are you sure that's what you want to ask? Also, `Take(1000)` will definitely not return 10 cities, but 1000 instead. – Nolonar Mar 12 '13 at 11:24
  • I could not understand whether "10" is hard-coded limit (magiv number) or it was a typo in in the article. Just that, without further linguistic equivoques (and there was no ready runnable sample to see it in debugger) – Fulproof Mar 12 '13 at 11:29

1 Answers1

2

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

Nolonar
  • 5,962
  • 3
  • 36
  • 55
  • Thanks, but I expected the comments about why specifically "10" was mentioned in the article – Fulproof Mar 12 '13 at 11:44
  • 1
    @Fulproof It is a typo. If you look at the code above, it's the same code, only without `AsOrdered()`. The text below describes this as `This query does not necessarily produce the first 1000 cities in the source sequence that meet the condition, but rather some set of 1000 cities that meet the condition`. Below, it suddenly speaks of `10 cities`. – Nolonar Mar 12 '13 at 11:48