The running result of Plinq is unordered, that is, it does not keep the sequence of the original set for operation (except for some special sorting operations ). The reason is that the concurrent execution of the thread is full of uncertainty. Splitting the original task into several parts and returning results at the same time will disrupt the original order. If you want to retain the order forcibly, some performance will be wasted. Plinq can be like this, but it is not like this by default.
First, let's look at a LINQ example:
VaRArr= New Int[] {1,2,3,4,5};
VaRRes=Arr.Where (I=>I! = 3);
The result is:
1, 2, 4, 5
The order is maintained. Plinq:
VaRRes=Arr.Asparallel ().Where (I=>I! = 3);
The order of results has changed:
1, 4, 5, 2
Use Plinq's asordered and asunordered commands to execute Plinq to retain the original set sequence or not.
Change the above Plinq:
VaRRes=Arr.Asparallel ().Asordered ().Where (I=>I! = 3);
The result is: 1, 2, 4, 5.
However, if the Plinq set is sorted, subsequent operations will automatically keep the order, just as asordered is called.
VaRRes=Arr.Asparallel ().Orderby (I=>I).Where (I=>I! = 3);
The result is: 1, 2, 4, 5.
Note that some Plinq methods are of little significance if they are not executed sequentially, such as the reverse method:
VaRRes=Arr.Asparallel ().Reverse ();
The result is:
5, 3, 2, 1, 4