Tip This is the easiest (and normally the best) way to get a string array containing each file name.
Array The identifier "fns" is used to reference the string array. An descriptive word would be better style.
C# program that sorts files by size
static void Main()
// Directory of files.
const string dir = "C:\\site";
// File names.
string fns = Directory.GetFiles(dir);
// Order by size.
var sort = from fn in fns
orderby new FileInfo(fn).Length descending
// List files.
foreach (string n in sort)
}(List of all files in the directory)
Understanding query syntax. We use LINQ syntax to order the string array by each Length value from the FileInfo of each file. We can use any C# expression in the query orderby part.