我下面的代码有效,但我担心它的做法不好或可能导致内存问题。但是以我有限的知识,这是我找到的最好的方法。可以做得更好吗?
谢谢
static void Main()
{
// Directory of files.
const string dir = @"C:\Test";
// File names.
string[] fns = Directory.GetFiles(dir);
// Order by size.
var sort = from fn in fns
orderby new FileInfo(fn).Length descending
select fn;
// List files.
foreach (string n in sort)
{
Console.Write(n);
Console.Write(" ");
FileInfo f = new FileInfo(n);
long file = f.Length;
Console.WriteLine(file);
}
Console.ReadLine();
}