c# - How to sort IEnumerable<FileInfo> testList? -


directoryinfo dir = new directoryinfo("c:\temp"); ienumerable<fileinfo> fileslist = dir.getfiles("*.zip", searchoption.topdirectoryonly);    

i tried testlist.orderby(f=>f.name) doesn't work. gives me error.

i tried ... doesn't work. gives me error

you had right idea, using linq , orderby, , experienced errors in other part of code. 1 culprit unescaped backslash in path, @ or \\ needed.

the following block of code runs without error in linqpad filter , sort .txt files in c:\temp folder. changing orderby orderbydescending reverses results expected.

void main() {     directoryinfo dir = new directoryinfo(@"c:\temp");     ienumerable<fileinfo> fileslist = dir.getfiles("*.txt", searchoption.topdirectoryonly);      // iterate on sorted set     foreach(var fileinfo in fileslist.orderby(fileinfo => fileinfo.name))     {         console.writeline(fileinfo.name);     } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -