Partitioning refers to the operations of dividing an input sequence into two sections, without rearranging the elements, and then returning one of the sections.
Skip
Skips elements up to a specified position in a sequence.
Method Syntax
// Skip
var numbers = new int[] { 1, 2, 3, 4, 5 };
var skipped = numbers.Skip(3);
// skipped = { 4, 5 }
Query Syntax
// Not applicable.
SkipWhile
Skips elements based on a predicate function until an element does not satisfy the condition.
Method Syntax
// Skip
var numbers = new int[] { 1, 3, 5, 2, 1, 3, 5 };
var skipLeadingOdds = numbers.SkipWhile(n => n % 2 != 0);
// skipLeadingOdds = { 2, 1, 3, 5 }
Query Syntax
// Not applicable.
Take
Takes elements up to a specified position in a sequence.
Method Syntax
// Take
var numbers = new int[] { 1, 2, 3, 4, 5 };
var taken = numbers.Take(3);
// taken = { 1, 2, 3 }
Query Syntax
// Not applicable.
TakeWhile
Takes elements based on a predicate function until an element does not satisfy the condition.
Method Syntax
// TakeWhile
var numbers = new int[] { 1, 3, 5, 2, 1, 3, 5 };
var takeLeadingOdds = numbers.TakeWhile(n => n % 2 != 0);
// takeLeadingOdds = { 1, 3, 5 }
Query Syntax
// Not applicable.