I’ve look around for a solution this problem and although I’ve found similar I couldnt find an answer to this specific problem. I’ve generalised the problem but it goes something as follows:
I have the following int[]
[423]
[234]
[5]
[79]
[211]
[1001]
I would like to use linq to only select the entries that are less than 200 or greater than 300 and then order by the original array index so that the final array is guranteed to be:
[423]
[5]
[79]
[1001]
LINQ to object preserves the order in selection, so a simple where clause would do the job.
Order Preservation in PLINQ
In PLINQ, the goal is to maximize performance while maintaining correctness. A query should run as fast as possible but still produce the correct results. In some cases, correctness requires the order of the source sequence to be preserved; however, ordering can be computationally expensive. Therefore, by default, PLINQ does not preserve the order of the source sequence. In this regard, PLINQ resembles LINQ to SQL, but is unlike LINQ to Objects, which does preserve ordering.
But if you want, you can select the
indexwith the value and later useOrderByonindex