【文章內(nèi)容簡介】
Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = Aggregate s1 In persons Into p1 = Average() (Result) Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = Aggregate s1 In persons Into p1 = Count( = 19) (Result) ?Min,Max ? Min(取最小值 ) ? Min(取最大值 ) Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = Aggregate s1 In persons Into p1 = Max() (Result) Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = Aggregate s1 In persons Into p1 = Min() (Result) ?Sum ? Sum(加總 ) ? Using Sum With BuildType ? Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = Aggregate s1 In persons Into p1 = Sum() (Result) Dim nums() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim Result = Aggregate s1 In nums Into p1 = Sum(s1) (Result) ?以 Group結(jié)合 Sum運算 ? Aggregate是傳回單值 ? 如需傳回元素集 ,可使用 Group語句進行 ? 寫法與 Aggregate後面敘述幾乎相同 ?First ? First – 取得第一個元素 ? 如果沒有元素符合 ,First將會拋出例外 Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = (From s1 In persons Where = 18).First() () ?FirstOrDefault ? FirstOrDefault – 當(dāng)沒有元素時 ,回傳 Nothing,但不引發(fā)例外 Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = (From s1 In persons Where = 50).FirstOrDefault() If Not Result Is Nothing Then () End If ?Last,LastOrDefault ? Last – 取得查詢集的最後一個元素 ? LastOrDefault – 同 Last,但如果查詢集為空 ,那將回傳 Nothing Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = (From s1 In persons Where = 18).Last() () Dim persons = New List(Of Person) (New Person(code6421, 18, 001)) (New Person(tom, 28, 002)) (New Person(mary, 19, 002)) Dim Result = (From s1 In persons Where = 50).LastOrDefault() If Not Result Is Not