【原】list<T>排序

继承IComparable

#region IComparable
    
    public int CompareTo(object  obj)
    {
        if(obj is SceneAsset)
        {
            SceneAsset tempAsset = obj as  SceneAsset;
            return this.Position.z.CompareTo(tempAsset.Position.z);
        }
        throw new NotImplementedException("obj is not a Student!");
    }
    #endregion

xx.Sort();

2、

list.Sort(Delegate( ClassA a,ClassA b){a.Age.CompareTo(b.Age);});

3、

StudentCompare:IComparer<Student>
{
  public int Compare(Student a, Student b)
  {
    return a.Age.CompareTo(b.Age);
  } 
}

使用 list.Sort(new StudentCompare());
list.Sort(0,3,new StudentCompare()) 按范围排序

 

 

posted @ 2014-05-12 16:32  U_探索  阅读(319)  评论(0编辑  收藏  举报