Is it possible using LINQ expression to skip some elements from the middle of the sequence? I want to Take N elements, then Skip M elements, then take the rest of the sequence. I know that I can write my own function for that but I wonder is it possible to do it using only built-in functions?
One way is to use the index:
sequence.Select((value, index) => new {value, index})
.Where(x => x.index < startOfRange || x.index > endOfRange)
.Select(x.value);
Or, even simpler: (can't believe I didn't think of that the first time)
sequence.Where((value, index) => index < startOfRange || index > endOfRange)
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