📜  LINQ元素运算符

📅  最后修改于: 2021-01-06 05:27:09             🧑  作者: Mango

LINQ元素运算符

在LINQ中,元素运算符用于基于列表的索引值返回列表的第一个和最后一个元素或集合中的单个元素或特定元素。

在LINQ中,我们有不同类型的元素运算符可用。这些是:

  • 第一
  • 第一或默认
  • 持续
  • LastOrDefault
  • ElementAt
  • ElementAtOrDefault
  • 单或反
  • 默认值

通过使用这些元素运算符,我们可以获得特定位置的项目列表/集合。下表显示了与元素运算符有关的更多详细信息。

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.