{"id":1270,"date":"2017-09-02T10:03:24","date_gmt":"2017-09-02T02:03:24","guid":{"rendered":"http:\/\/39.100.100.179\/?p=1270"},"modified":"2017-09-02T10:05:07","modified_gmt":"2017-09-02T02:05:07","slug":"%e4%bd%bf%e7%94%a8linq%e8%bf%9b%e8%a1%8c%e5%a4%9a%e5%ad%97%e6%ae%b5list%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=1270","title":{"rendered":"\u4f7f\u7528Linq\u8fdb\u884c\u591a\u5b57\u6bb5List\u6392\u5e8f"},"content":{"rendered":"<p>\u6709\u65f6\u6211\u4eec\u4f1a\u9047\u5230\u591a\u4e2a\u5b57\u6bb5\u8fdb\u884c\u6392\u5e8f\uff0c\u6bd4\u5982\u5148\u6309\u7167\u82f1\u96c4\u54c1\u7ea7\u6392\u5e8f\u3001\u518d\u6309\u7167\u82f1\u96c4\u661f\u7ea7\u6392\u5e8f\u3001\u6700\u540e\u6309\u7167\u82f1\u96c4\u7b49\u7ea7\u6392\u5e8f\u7b49\u7b49<\/p>\n<p>\u8fd9\u65f6\u5019\u4e0d\u59a8\u4f7f\u7528Linq\u5b8c\u6210\u8be5\u64cd\u4f5c<\/p>\n<p>\u4e0b\u9762\u7684\u6392\u5e8f\u662f\u5148\u6309\u662f\u5426\u5b58\u6d3b\uff0c\u518d\u6309id\u6392\u5e8f~~<\/p>\n<pre class=\"lang:c# decode:true\">using UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nclass Data\r\n{\r\n    public int id;      \r\n    public bool life;    \r\n\r\n    public Data(int id, bool life)\r\n    {\r\n        this.id = id;\r\n        this.life = life;\r\n    }\r\n}\r\n\r\npublic class Test : MonoBehaviour {\r\n\r\n    List&lt;Data&gt; dataList = new List&lt;Data&gt;() { new Data(1, false), new Data(5, true), new Data(3, true), new Data(4, false) };\r\n\r\n    \/\/ Use this for initialization\r\n    void Start()\r\n    {\r\n\r\n        \/\/ \u5347\u5e8f\u6392\u5e8f\r\n        dataList = dataList.OrderBy(i =&gt; i.life).ThenBy(i =&gt; i.id).ToList();   \/\/ \u5148\u6309life\u6392\u5e8f\uff0c\u7136\u540e\u518d\u6309id\u6392\u5e8f\r\n\r\n        for (int i = 0; i &lt; dataList.Count; i++)\r\n        {\r\n            Debug.Log(\"\u5347\u5e8f\uff1a\" + dataList[i].life + \" \" + dataList[i].id);\r\n        }\r\n\r\n        Debug.Log(\"~~~~~~~~~~~~~~~~~~~~~\");\r\n\r\n        \/\/ \u964d\u5e8f\u6392\u5e8f\r\n        dataList = dataList.OrderByDescending(i =&gt; i.life).ThenByDescending(i =&gt; i.id).ToList();\r\n\r\n        for (int i = 0; i &lt; dataList.Count; i++)\r\n        {\r\n            Debug.Log(\"\u964d\u5e8f\uff1a\" + dataList[i].life + \" \" + dataList[i].id);\r\n        }\r\n    }\r\n}<\/pre>\n<p><a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/09\/QQ\u622a\u56fe20170831195802.png\" data-lightbox=\"image_lg\"><img title=\"\u4f7f\u7528Linq\u8fdb\u884c\u591a\u5b57\u6bb5List\u6392\u5e8f - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u4f7f\u7528Linq\u8fdb\u884c\u591a\u5b57\u6bb5List\u6392\u5e8f - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"aligncenter size-full wp-image-1272\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/09\/QQ\u622a\u56fe20170831195802.png\" width=\"376\" height=\"303\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/09\/QQ\u622a\u56fe20170831195802.png 376w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/09\/QQ\u622a\u56fe20170831195802-300x242.png 300w\" sizes=\"(max-width: 376px) 100vw, 376px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\u6211\u4eec\u4f1a\u9047\u5230\u591a\u4e2a\u5b57\u6bb5\u8fdb\u884c\u6392\u5e8f\uff0c\u6bd4\u5982\u5148\u6309\u7167\u82f1\u96c4\u54c1\u7ea7\u6392\u5e8f\u3001\u518d\u6309\u7167\u82f1\u96c4\u661f\u7ea7\u6392\u5e8f\u3001\u6700\u540e &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=1270\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28],"tags":[291,292,289,290],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1270"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1270"}],"version-history":[{"count":2,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1270\/revisions"}],"predecessor-version":[{"id":1273,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1270\/revisions\/1273"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1270"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}