List.Sort()小技巧

来源:互联网 发布:centos解压rar 编辑:程序博客网 时间:2024/06/08 02:17

List<UIPanel> list = parentGo.GetComponents<UIpanel>();

list.Sort(

delegate(UIPanel a, UIPanel b)

return a.depth.CompareTo(b.depth);

});

list.Sort((UIPanel a,UIPanel b )=> a.depth.CompareTo(b.depth));


只要将后面的参数与前面的参数进行对比,这样返回的结果,将是一个从小到大排列了。这种方式适合于字符串等许多类型的排序。

和大家分享一下 :)


0 0
原创粉丝点击