Would
int[] nums = { 2, 3, 3, 4, 2, 1, 6, 7, 10 };
var distinct = nums.Distinct();
always return 2, 3, 4, 1, 6, 7, 10
in that order?
Would
int[] nums = { 2, 3, 3, 4, 2, 1, 6, 7, 10 };
var distinct = nums.Distinct();
always return 2, 3, 4, 1, 6, 7, 10
in that order?
The defined behavior of Distinct is that it will return an unordered collection (Documentation).
However the current implementation of Distinct in Linq to Objects will preserve order. This is not guaranteed for other LINQ providers though and the behavior should not be relied upon.
In general: no, but in your case (with an int array): probably yes. I bet they are just enumerating the collection and disregarding items they've already come across. But don't count on that behavior across different versions of .NET or for different types of collections.
As JaredPar pointed out in his answer, the result is specified as unordered. If you want some specific ordering, you need to sort them afterward using whatever algorithm makes sense in your case.
I think the word "unordered" means the same order of the original sequence.
Hence, the caller should decide whether to sort the result or not.