C# Get a folder or file list which finished sequence line. 直接得到 排序后 的 文件列表

来源:互联网 发布:淘宝网店推广方法与营销技巧 编辑:程序博客网 时间:2024/05/16 09:22

public class DirComparer : System.Collections.IComparer

{

public int Compare(object x, object y)

{

return y.ToString().CompareTo(x.ToString());

}

}

       DirectoryInfo di 
= new DirectoryInfo(“FolderPath”);
       ArrayList dirArr 
= new ArrayList(di.GetDirectories());
       dirArr.Sort(
new DirComparer());
 

 

IComparer Interface :

 

This interface is used in conjunction with the Array.Sort and Array.BinarySearch methods. It provides a way to customize the sort order of a collection. See the Compare method for notes on parameters and return value.

The default implementation of this interface is the Comparer class. For the generic version of this interface, see System.Collections.Generic.IComparer<T>.