LINQ元素运算符

LINQ元素运算符 首页 / LinQ入门教程 / LINQ元素运算符

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

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

  1. First
  2. FirstOrDefault
  3. Last
  4. LastOrDefault
  5. ElementAt
  6. ElementAtOrDefault
  7. Single
  8. SingleOrDefualt
  9. DefaultfEmpty
LINQ 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.





祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

硅谷产品实战36讲 -〔曲晓音〕

Android开发高手课 -〔张绍文〕

Node.js开发实战 -〔杨浩〕

MongoDB高手课 -〔唐建法(TJ)〕

小马哥讲Spring核心编程思想 -〔小马哥〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

用户体验设计实战课 -〔相辉〕

性能优化高手课 -〔尉刚强〕

HarmonyOS快速入门与实战 -〔QCon+案例研习社〕

好记忆不如烂笔头。留下您的足迹吧 :)