LINQ TakeWhile Partition Operator
In LINQ, TakeWhile Operator is used to get the elements from the list/collection of the data source as long as the specified condition is holding the expression.
Syntax of LINQ TakeWhile Operator
The syntax of using the LINQ TakeWhile operator is to get the elements from the list, based on the specified condition.
From the above syntax, we are getting the elements from the list where the elements starts with "U".
Example of LINQ TakeWhile in Method Syntax
Here is the example of using the LINQ TakeWhile in method syntax to get the elements from the list/collection.
In the above example, we used TakeWhile () operator and a lambda expression in which we specified the condition which will select the countries that starts with "U." So, it returns only the first two elements.
Example of LINQ TakeWhile in Query Syntax
Here is the example of using the LINQ TakeWhile Operator in query syntax to get the elements from the list.
After executing the above program, we get the output as shown below: