I know this is simple, but my mind is playing tricks on me right now. If we have a flat list of objects with the properties GroupSortIndex and ItemSortIndex (within the group) and we want to find the first item in the list, what’s the Linq/lambda for that?
About all I can think of is (meta, not literal code…)
var soughtItem = Source.OrderBy(ItemSortIndex).OrderBy(GroupSortIndex).ToList()[0]
…but that just looks so wrong to me for some reason.
You can use
IOrderedEnumerable.ThenBy(Note: anIOrderedEnumerableis returned fromIEnumerable.OrderBy):This orders first by the group and then by the item. You should use
FirstOrDefaultif the sequence can be empty. OtherwiseFirstraises an exception.(i’ve assumed that you want to order first by group and then by the item instead, since the ItemSortIndex is the index of the item within the group(as mentioned))