Using PLINQ C# parallel queries are ordered or unordered depending on how you construct them. There is some information on MSDN here regarding order preservation in PLINQ.
I find this confusing and tricky to manage. In my mind collections where the order is significant are sequences and collections where order is not significant are bags (or if there are no duplicates, then they might be sets).
The operations on bags and sequences are different, and have different complexity characteristics especially when implemented as parallel algorithms.
In other words I think that ordered and unordered collections should be different types, and that this would simplify things. Is there a reason why everything in PLINQ is unified as simply a “ParallelQuery()”?
It’s simpler. I suppose 2 types would have been possible but at some considerable expense. And would it be any easier to use?
When you process a sequence in Parallel then by default you give up Order. You ought to be aware that re-establishing sequence is expensive and that it should require some extra steps.
But when you need it, adding an
.AsOrdered()seems much less of a pain than copying (!) your data to another collection first.