码迷,mamicode.com
首页 > 其他好文 > 详细

C# 中对 ArrayList 的排序

时间:2014-08-09 00:02:54      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   div   时间   new   log   

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

 

C# 中对 ArrayList 的排序,布布扣,bubuko.com

C# 中对 ArrayList 的排序

标签:style   blog   color   ar   div   时间   new   log   

原文地址:http://www.cnblogs.com/zsk526/p/3900295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!