當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Enumerable.Aggregate方法代碼示例

本文整理匯總了VB.NET中System.Linq.Enumerable.Aggregate方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Enumerable.Aggregate方法的具體用法?VB.NET Enumerable.Aggregate怎麽用?VB.NET Enumerable.Aggregate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了Enumerable.Aggregate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: AggregateEx3

Sub AggregateEx3()
    Dim fruits() As String =
    {"apple", "mango", "orange", "passionfruit", "grape"}

    ' Determine whether any string in the array is longer than "banana".
    Dim longestName As String =
    fruits.Aggregate("banana",
                     Function(ByVal longest, ByVal fruit) _
                         IIf(fruit.Length > longest.Length, fruit, longest),
                     Function(ByVal fruit) fruit.ToUpper())

    ' Display the output.
    Console.WriteLine($"The fruit with the longest name is {longestName}")
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Linq,代碼行數:14,代碼來源:Enumerable.Aggregate

輸出:

The fruit with the longest name is PASSIONFRUIT

示例2: AggregateEx2

Sub AggregateEx2()
    ' Create an array of Integers.
    Dim ints() As Integer = {4, 8, 8, 3, 9, 0, 7, 8, 2}

    ' Count the even numbers in the array, using a seed value of 0.
    Dim numEven As Integer =
    ints.Aggregate(0,
                   Function(ByVal total, ByVal number) _
                       IIf(number Mod 2 = 0, total + 1, total))

    ' Display the output.
    Console.WriteLine($"The number of even integers is {numEven}")
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Linq,代碼行數:13,代碼來源:Enumerable.Aggregate

輸出:

The number of even integers is 6

示例3: AggregateEx1

Sub AggregateEx1()
    Dim sentence As String =
    "the quick brown fox jumps over the lazy dog"
    ' Split the string into individual words.
    Dim words() As String = sentence.Split(" "c)
    ' Prepend each word to the beginning of the new sentence to reverse the word order.
    Dim reversed As String =
    words.Aggregate(Function(ByVal current, ByVal word) word & " " & current)

    ' Display the output.
    Console.WriteLine(reversed)
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Linq,代碼行數:12,代碼來源:Enumerable.Aggregate

輸出:

dog lazy the over jumps fox brown quick the


注:本文中的System.Linq.Enumerable.Aggregate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。