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.

OperatorsDescription
FirstIt returns the first element in sequence or from the collection based on the condition.
FirstOrDefaultIt is the same as First, but it returns the default value in case when no element is found in the collection.
LastIt returns the last element in sequence or the last element based on the matching criteria.
ElementAtIt returns an element from the list based on the specific index position.
ElementAtOrDefaultIt 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.
SingleIt returns the single specific element from the collection.
SingleOrDefaultIt is the same as Single, but it returns the default value in case if no element is found in the collection.
DefaultfEmptyIt returns the default value in case if the list or collection contains empty or null values.





Latest Courses