在LINQ中,元素运算符用于返回列表的第一个和最后一个元素,或者返回集合中的单个元素,或者基于集合中的索引值返回特定元素。
在LINQ中,我们有不同类型的元素运算符可用。这些是:
通过使用这些元素运算符,我们可以获得特定位置的项目列表/集合。下表显示了与元素运算符相关的更详细信息。
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. |
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
HarmonyOS快速入门与实战 -〔QCon+案例研习社〕