Will the result of a LINQ query always be guaranteed to be in the correct order?

c#, linq

Solution

- For LINQ to Objects: Yep.

- For Parallel LINQ: Nope.

- For LINQ to Expression Trees (EF, L2S, etc): Nope.

Problem

Question: Will the result of a LINQ query always be guaranteed to be in the correct order? Example: ``` int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n; ``` Now, when we walk through the entries of the query result, will it be in the same order as the input data `numbers` is ordered? ``` foreach (var x in lowNums) { Console.WriteLine(x); } ``` If someone can provide a note on the ordering in the documentation, this would be perfect.

Original source

Related problems