例: 代わりにこのコードを使用してください。 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)の場合は、LocationとFacilityも取得するためにIncludeを追加する必要があります。 – Max