继承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(,,new StudentCompare()) 按范围排序