using System.Collections.Generic;
using System.IO;
using System.Linq;
class SortFiles
{
public IEnumerable<FileInfo> Sort()
{
// Set the directory you want to search
DirectoryInfo di = new DirectoryInfo(@"C:\");
// Get all of the .jpg files from the directory and order
// them by file name in descending order
IEnumerable<FileInfo> files =
di.GetFiles("*.jpg").OrderByDescending(e => e.Name);
return files;
}
}
You can sort it by name, creation time, length, or any other FileInfo property. You can find many other LINQ examples here:
http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx