I have a list of objects that are in the order that I want to select them, but not sure how to do it...
For example, if I have List<obj> mylist
where obj has properties:
start,
end
How do I create a list of numbers that contains
start1, end1, start2, end2, start3, end3, etc...
where start1, end1 are the int properties from the first object, start2, end2 are the number properties from the second object, and so on.. I know how to do this in a foreach loop, but not sure how to do so in Linq.
You can use SelectMany. Something along these lines:
var result = mylist
.SelectMany(o => new[] { o.start, o.end })
.ToList();
Demo @sharplab.io
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With