Javatpoint Logo
Javatpoint Logo

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.

C# Code

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.

C# Code

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.

OUTPUT:

LINQ TakeWhile Partition Operator

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.

OUTPUT:

After executing the above program, we get the output as shown below:

LINQ TakeWhile Partition Operator
Next TopicLINQ Skip Operator




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA