ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the custom aggregation using LINQ Aggregate() method

Here, we are going to demonstrate the custom aggregation using LINQ Aggregate() method in VB.Net.
Submitted by Nidhi, on January 27, 2021

In this program, we will use the Aggregate() method to perform custom aggregation on specified list elements, here we will perform aggregation on integers and strings.

Program/Source Code:

The source code to demonstrate the custom aggregation using LINQ Aggregate() method is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the custom aggregation 
'using LINQ Aggregate() method.

Imports System
Imports System.IO
Imports System.Linq

Module Module1
    Sub Main()
        Dim countryList As IList(Of String) = New List(Of String) From {
                                                            "India",
                                                            "USA",
                                                            "UK",
                                                            "CANADA",
                                                            "SRI-LANKA"
                                                        }
        Dim Countries = countryList.Aggregate(Function(c1, c2) c1 + ", " + c2)

        Console.WriteLine("Country names separated by comma:")
        Console.WriteLine(Countries)

        Dim Marks() As Integer = {67, 78, 45, 88, 91}

        Dim MarksTotal = Marks.Aggregate(Function(m1, m2) m1 + m2)

        Console.WriteLine("Marks Total: " & MarksTotal)

    End Sub
End Module

Output:

Country names separated by comma:
India, USA, UK, CANADA, SRI-LANKA
Marks Total: 369
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a Main() function. The Main() function is the entry point for the program.

In the Main() function, We created the list of countries and the list of Marks of a student. Here, we used the Aggregate() method to separate countries using a comma and perform the addition of marks and get the total of marks. After that, we printed the result on aggregation on the console screen.

VB.Net LINQ Query Programs »



ADVERTISEMENT




ADVERTISEMENT


Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.