I've been trying to sort a iEnumerable using another iEnumerable as a point of reference.
My first iEnumerable "combinations" (the one which i'd like to sort) holds 67 items but the only important property of these items is InventSizeName.
My 2nd iEnumerable "sizes" holds 5 items and the items looks like this
Id Name SortOrder
What I would like to do is to sort combinations by using sizes.SortOrder where sizes.Name == combinations.InventSizeName.
The closest I've been is
var sorted = combinations
.Zip(sizes, (c, s) => new { com = c, siz = s })
.OrderBy(v => v.siz.Order)
.Select(v => v.com)
.ToList();
This however doesn't compare the properties and set the correct order (obviously) and it gives me a List with only 5 entries.
I'm sorry that this question is badly written but I hope anyone of you guys could help me out here.
I think the easiest way is to join the two IEnumerables
var sorted = from c in combinations
join s in sizes on c.Name equals s.InventSizeName
orderby s.Order
select c;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.