View Single Post
 
Old 09-01-2013, 08:47 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Short answer: there is, but it won't help.

There's an OrderBy() method that does the same thing the "SQL syntax" does and works like SelectMany(); in this case it takes a function that returns the value used for sorting.

Unfortunately I don't think it will make this go any faster. Directory.GetFiles() returns its results all at once, which means you pay the biggest performance penalty up-front before you've even sorted. There's a Directory.EnumerateFiles() that returns them one at a time, but in order to sort OrderBy() has to iterate over the entire collection anyway.

So as long as "sorted" is a requirement, no variation of the code is going to be significantly faster than any other.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote