LINQ - The Take and Skip methods

 

LINQ - The Take and Skip methods

The partitioning LINQ methods are used to fetch or skip elements from the beginning of an enumerable list while a condition yields true. The Take and Skip methods, and TakeWhile and SkipWhile methods, are complements of one another, meaning that if we concatenate the results from any of these two functional complements we will end up with the same sequence that we started with. These methods are available from .NET Framework 3.5 and onwards.

These are the variations of the four methods that we will be looking at in this article.

  • Take<T>
  • The Take<T> Method with a Nested Query
  • TakeWhile<T>
  • TakeWhile<T> Indexed
  • Skip<T>
  • Skip<T> Nested
  • SkipWhile<T>
  • SkipWhile<T> Indexed

The Take<T> Method

The Take method is used to fetch items from the beginning of an enumerable sequence for as long as the limiting condition is true. The return value is an IEnumerable<T> containing the items satisfying the...

Continue Reading...
Close

50% Complete

Two Step

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.