这里以Linq为例的对象。 ToList
确实没有改变列表的排序。
List<CableList> Runlist = new List<CableList>
{
new CableList { Location = new Location
{ Facility = new Facility { FacilityTitle = "titel3" }}},
new CableList { Location = new Location
{ Facility = new Facility { FacilityTitle = "titel2" }}},
new CableList { Location = new Location
{ Facility = new Facility { FacilityTitle = "titel5" }}},
new CableList { Location = new Location
{ Facility = new Facility { FacilityTitle = "titel1" }}},
new CableList { Location = new Location
{ Facility = new Facility { FacilityTitle = "titel9" }}}
};
System.Diagnostics.Debug.WriteLine("Before order:");
foreach (var itm in Runlist)
System.Diagnostics.Debug.WriteLine(itm.Location.Facility.FacilityTitle);
var orderedResult = Runlist.OrderBy(x => x.Location.Facility.FacilityTitle)
.Skip(1)
.Take(4)
.ToList();
System.Diagnostics.Debug.WriteLine("After order:");
foreach (var itm in orderedResult)
System.Diagnostics.Debug.WriteLine(itm.Location.Facility.FacilityTitle);
输出:
Before order:
titel3
titel2
titel5
titel1
titel9
After order:
titel2
titel3
titel5
titel9
来源
2016-12-02 14:30:43
dee
那是什么'OrderBy'函数的输出? – RandomStranger
你把它分配给任何东西吗?它会创建一个新的列表。 – juharr
您是否将您的列表对象与它是实例的类相同?你确定位置和设施是否为空?如果这是Linq to Sql(EF),则应该添加Include以检索Location和Facility。 – Max