Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the Average extension
Here, we are going to demonstrate the Average extension in VB.Net.
Submitted by Nidhi, on January 24, 2021 [Last updated : March 08, 2023]
VB.Net – Average Extension
In this program, we will use the Average() extension method of the "System.Linq" namespace to calculate the average of array elements.
Program/Source Code:
The source code to demonstrate the Average extension is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of Average Extension
'VB.NET program to demonstrate the
'Average extension.
Imports System
Imports System.IO
Imports System.Linq
Module Module1
Sub Main()
Dim intVals() As Integer = {50, 20, 40, 35, 10, 27, 60}
Dim avg As Double = intVals.Average()
Console.WriteLine("Average of array elements: {0}", avg)
End Sub
End Module
Output
Average of array elements: 34.5714285714286
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 average of array elements using the Average() extension method of the "System.Linq" namespace. After that, we printed the calculated average on the console screen.
VB.Net LINQ Query Programs »