Javatpoint Logo
Javatpoint Logo

LINQ Element Operators

In LINQ, element operators are used to returning the first and last element of the list or single element from the collection or a specific element based on the index value from the collection.

In LINQ, we have different types of element operators available. These are:

  1. First
  2. FirstOrDefault
  3. Last
  4. LastOrDefault
  5. ElementAt
  6. ElementAtOrDefault
  7. Single
  8. SingleOrDefualt
  9. DefaultfEmpty
LINQ Element Operators

By using these element operators, we can get the list/collection of items at the specific position. The following table shows more detailed information related to the element operators.

Operators Description
First It returns the first element in sequence or from the collection based on the condition.
FirstOrDefault It is the same as First, but it returns the default value in case when no element is found in the collection.
Last It returns the last element in sequence or the last element based on the matching criteria.
ElementAt It returns an element from the list based on the specific index position.
ElementAtOrDefault It is the same as ElementAt, but it returns the default value in case if no element is present at the specified index of the collection.
Single It returns the single specific element from the collection.
SingleOrDefault It is the same as Single, but it returns the default value in case if no element is found in the collection.
DefaultfEmpty It returns the default value in case if the list or collection contains empty or null values.





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA