Using linq, How can I sort an array and after that return all numbers that are smaller then X
For sorting I use that:(is it a good way?)
var sorted = (from number in array orderby number ascending select number).ToArray();
So i have it sorted in ‘sorted’ array.
how can i return all numbers in it that are smaller then X.
Why do you want to sort before you filter? That is less efficient than to filter first and order the rest:
or in query syntax:
Order of LINQ extension methods does not affect performance? (the title is misleading, actually
OrderByis one of the exceptions where the order matters as E.Lippert explains in his answer)