Javatpoint Logo
Javatpoint Logo

LINQ First() Element

In LINQ, the First () method/operator is used to return the first element from the sequence of the items in the list or collection or the first element in the sequence of items in the list based on the specified condition. In case if no element is present in the list/collection based on the specified condition, then LINQ FIRST () method will throw an error.

Syntax of LINQ FIRST () method

The syntax of the first method to get the first element from the list is:

From the above syntax, we are getting the first element from the "objList" collection using the LINQ FIRST () method.

Example of LINQ FIRST () method

Here is the example of the LINQ FIRST () operator in method syntax to get the first element from the collection.

C# Code

From the above example, we are trying to get the first element from the collection of "objList" by using the LINQ FIRST () operator in method syntax.

Output:

The result of the LINQ FIRST () operator in method syntax is as shown below:

LINQ First() Element

Example of LINQ FIRST () operator in Query Syntax

Here is the example of the LINQ FIRST () operator in method syntax to get the first element from the collection.

Output:

The result of the LINQ FIRST () operator in method syntax is as shown below:

LINQ First() Element





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA