Element Operators

ElementAt

Returns the element at a specified index in a collection

ElementAtOrDefault

Returns the element at a specified index in a collection or a default value if the index is out of range.

First

Returns the first element of a collection, or the first element that satisfies a condition.

FirstOrDefault

Returns the first element of a collection, or the first element that satisfies a condition. Returns a default value if index is out of range.

Last

Returns the last element of a collection, or the last element that satisfies a condition

LastOrDefault

Returns the last element of a collection, or the last element that satisfies a condition. Returns a default value if no such element exists.

Single

Returns the only element of a collection, or the only element that satisfies a condition.

SingleOrDefault

Returns the only element of a collection, or the only element that satisfies a condition. Returns a default value if no such element exists or the collection does not contain exactly one element.

时间: 2024-12-23 06:21:35

Element Operators的相关文章

101个LINQ例子

Restriction Operators Where - Simple 1 public void Linq1() {    int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };    var lowNums =        from n in numbers        where n < 5        select n;    Console.WriteLine("Numbers < 5:");    foreac

Python开发程序:计算器

开发一个简单的python计算器 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )等类似公式后,必须自己解析里面的(),+,-,*,/符号和公式(不能调用eval等类似功能偷懒实现),运算后得出结果,结果必须与真实的计算器所得出的结果一致 #!/usr/bin/env python # -*- coding:utf-8 -*-

101个LINQ示例,包含几乎全部操作

Restriction Operators Where - Simple 1 public void Linq1() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n; Console.WriteLine("Numbers < 5:"); foreach (var x in lowNums) { Console.Wr

LINQ Operators之过滤(Filtering)

转:http://www.cnblogs.com/lifepoem/archive/2011/11/16/2250676.html 在本系列博客前面的篇章中,已经对LINQ的作用.C# 3.0为LINQ提供的新特性,还有几种典型的LINQ技术:LINQ to Objects.LINQ to SQL.Entity Framework进行了比较详细的介绍,至此,我们应该了解了各种LINQ技术之间的联系和区别.千里之行始于足下,这些基础理论是理解和使用LINQ 的关键.但是我们在前面的文章中对于LIN

LINQ之路14:LINQ Operators之排序和分组(Ordering and Grouping)

本篇继续LINQ Operators的介绍,这里要讨论的是LINQ中的排序和分组功能.LINQ的排序操作符有:OrderBy, OrderByDescending, ThenBy, 和ThenByDescending,他们返回input sequence的排序版本.分组操作符GroupBy把一个平展的输入sequence进行分组存放到输出sequence中. 排序/Ordering IEnumerable<TSource>→IOrderedEnumerable<TSource> O

Flink之Stateful Operators

Implementing Stateful Functions source function的stateful看官网,要加lock Declaring Keyed State at the RuntimeContext state可通过 rich functions .Listcheckpoint和CheckpointFunction获得. 在Flink中,当对某个数据进行处理时,从上下文中获取state时,只会获取该数据key对应的state. 四种Keyed State: ValueSta

215. Kth Largest Element in an Array

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.Note:You may assume k is always valid, 1 ≤ k ≤ array's le

LeetCode OJ 162. Find Peak Element

A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its index. The array may contain multiple peaks, in that case return the index to any one of the peaks is fi

LeetCode(7): Majority Element

Majority Element: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always exist in the array. 题意:找出给定数组中的