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());

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM