LINQ | Partition Operator | TakeWhile
In LINQ, partition operators are used for separating the given sequence into two portions without sorting the elements and return one of the portions. The Standard Query Operators supports 4 different types of partition operators:
The TakeWhile operator is used to return elements from the given sequence as long as it satisfies the given condition and when the condition satisfy it skips those elements which do not satisfy the given condition. This method is overloaded in two different ways:
- TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>): This method is used to return elements from the given sequence as long as a specified condition is true.
- TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource, Int32, Boolean>): This method is used to return elements from the given sequence as long as a specified condition is true. The index value of the elements are used in the logic of the predicate function.
- It does not support query syntax in C# and VB.Net languages. But you can use the TakeWhile method to query variable or you can wrap your query in brackets and then the call TakeWhile method.
- It support method syntax in both C# and VB.Net languages.
- It present in both the Queryable and Enumerable class.
- It is implemented by using deferred execution.
- It will throw an ArgumentNullException if the source or the condition is null.
New Sequence: 13 45 56 67
Employee Name: Anjita Employee Name: Soniya Employee Name: Rohit
My Personal Notes arrow_drop_up
Please Login to comment...