首页 > 代码库 > C# 中对 ArrayList 的排序

C# 中对 ArrayList 的排序

ArrayList 元素

//目录条目类public class FolderItem{    public string filename;    public string filetype;    public int size;    public int number;    public FolderItem(string filename, string filetype, int size, int number)    {        this.filename = filename;        this.filetype = filetype;        this.size = size;        this.number = number;    }    }

排序方法类

//目录上传时间排序public class FolderItemCompare : IComparer{    public int Compare(object manA, object manB)    {        FolderItem man1 = (FolderItem)manA;        FolderItem man2 = (FolderItem)manB;        return man1.number.CompareTo(man2.number);    }}

调用:

ArrayList arrList = new ArrayList();arrList.Add(item);//...arrList.Sort(new FolderItemCompare());