Select the next N elements of an IEnumerable<T>

Posted by sassafrass on Stack Overflow See other posts from Stack Overflow or by sassafrass
Published on 2009-03-07T12:33:33Z Indexed on 2010/05/18 18:10 UTC
Read the original article Hit count: 153

Filed under:
|

Say you've got some IEnumerable called S of length N. I would like to select all continuous subsequences of length n <= N from S.

If S were, say, a string, this'd be pretty easy. There are (S.Length - n + 1) subsequences of length n. For example, "abcdefg" is length (7), so that means it has (5) substrings of length (3): "abc", "bcd", "cde", "def", "efg".

But S could be any IEnumerable, so this route isn't open. How do I use extension methods to solve this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about extension-methods