ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the Sum() extension method

Here, we are going to demonstrate the Sum() extension method in VB.Net.
Submitted by Nidhi, on January 24, 2021

In this program, we will use the Sum() extension method of the "System.Linq" namespace to calculate the sum of array elements.

Program/Source Code:

The source code to demonstrate the Sum() extension method is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the 
'Sum() extension method.

Imports System
Imports System.IO
Imports System.Linq

Module Module1
    Sub Main()
        Dim intVals() As Integer = {50, 20, 40, 35, 10, 27, 60}

        Dim s As Double = intVals.Sum()
        Console.WriteLine("Sum of array elements: {0}", s)
    End Sub
End Module

Output:

Sum of array elements: 242
Press any key to continue . . .

Explanation:

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

In the Main() function, we created an integer array that contains 7 elements. Here, we calculated the sum of array elements using the Sum() extension method of the "System.Linq" namespace. After that, we printed the calculated sum 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.