AsUnordered

在处理大量元素时,有序序列可能会损害性能。为了缓解这种情况,可以在不再需要序列顺序时调用 AsUnordered

var sequence = Enumerable.Range(1, 10000).Select(x => -1 * x); // -1, -2, ...
var evenNumbers = sequence.AsParallel()
                          .OrderBy(x => x)
                          .Take(5000)
                          .AsUnordered()
                          .Where(x => x % 2 == 0) // This line won't be affected by ordering
                          .ToList();