本文整理汇总了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
输出:
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
输出:
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
输出:
dog lazy the over jumps fox brown quick the