Using Aggregate Function in Linq

This Sample Allows you to use the aggregate function on arrays


Sub Main()
Dim numbers() As Integer = {10, 20, 33, 44, 33}

Dim sumAgg = numbers.Aggregate(Function(n, m) n + m)
Dim proAgg = numbers.Aggregate(Function(n, m) n * m)
Dim subAgg = numbers.Aggregate(Function(n, m) n - m)
Console.WriteLine("Sum Using Aggregate : " & sumAgg)
Console.WriteLine("Product Using Aggregate : " & proAgg)
Console.WriteLine("Subtraction Using Aggregate : " & subAgg)
'Similarly you can add any math's calculation to these arrays
'ArrayName.Aggregate(Function(a,b) a [operator] b)

End Sub


Only Works on Framework 3.5

Regards Hefin Dsouza


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: