我有一个对象List<MyObject>的列表,我希望根据MyObject的属性之一对该列表进行排序。因此,例如MyObject obj1, obj2, obj3 = new MyObject();obj1.Value = 0.2;obj2.Value = 2.2;obj3.Value = 1.3;..List 的顺序为List[0] = obj2;List[1] = obj3;List[2] = obj1;我可以使用.NET本机功能执行此操作,还是必须编写自己的搜索? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 1个选项OrderByyourList = yourList.OrderBy(x=>x.PropertyName).ToList();降序yourList = yourList.OrderByDescending(x=>x.PropertyName).ToList();2选项List.SortyourList.Sort((x,y)=>x.PropertyName.CompareTo(y.PropertyName));降序yourList.Sort((x,y)=>-x.PropertyName.CompareTo(y.PropertyName)); (adsbygoogle = window.adsbygoogle || []).push({});
10-08 09:43