How to use Maximun Aggregate operator in LINQ: Part 4

The next category in aggregate operator of LINQ is Aggregate operator which is used in by Two ways simple Aggregate , Aggregate Seed. In this article we discuss about these two categories.
  • First we discuss about the simple Aggregate operator by using a simple example. you can write this code in vb.net and by getting the output you understand the working of Average operator.

        EXAMPLE CODE          

          Module Module1
                Sub
Main()
                      Dim
DecimalNo() = {3.5, 7.8, 56.8, 8.9, 43.6}
                Dim
Multiplication = DecimalNo.Aggregate( _
                Function
(runningProduct, nextFactor) runningProduct * nextFactor)
                Console.WriteLine("Total Multiplication of all numbers: {0}"
, Multiplication)
                      Console
.ReadLine()
                End
Sub
          End
Module 

         OUTPUT          

           1.1.gif

Read more articles related LINQ Click Here

  • The second category of Aggregate operator is Aggregate Seed this operator is performing Calculus.

         EXAMPLE CODE

            Module Module1
                Sub
Main()
                     Dim
OpiningBalance = 200.0
               Dim
StratWithdraws() = {40, 20, 80, 100, 20, 140, 60}
               Dim ClosingBalance = StratWithdraws.Aggregate(OpiningBalance, Function
(Opening, Withdrawal) _
               (
If
(Withdrawal <= Opening, (Opening - Withdrawal), Opening)))
               Console.WriteLine("Closing balance: {0}"
, ClosingBalance)
                     Console
.ReadLine()
                End
Sub
           End
Module                                   

          OUTPUT

             1.2.gif

Read more articles related LINQ Click Here

Ebook Download
View all
Learn
View all