Call Array.Sort, passing in a comparison delegate:
Array.Sort(taskFiles, delegate(FileInfo f1, FileInfo f2) {
return f1.Name.CompareTo(f2.Name);
});
In C# 3 this becomes slightly simpler:
Array.Sort(taskFiles, (f1, f2) => f1.Name.CompareTo(f2.Name));
Or you can use a StringComparer
if you want to use a case-insensitive sort order:
Array.Sort(taskFiles,
(x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name));
(or use string.Compare(x.Name, y.Name, true)
, or any of the many other ways of comparing strings :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…