• 【原】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()) 按范围排序
  • 相关阅读:
    反射详解六
    反射详解五
    反射详解四
    反射详解三
    反射详解二
    mysql行转列
    mysql增删改查
    视图的使用
    js过滤
    错误集
  • 原文地址:https://www.cnblogs.com/U-tansuo/p/List_Sort.html
Copyright © 2020-2023  润新知