Enumerable.Average Method (IEnumerable(Of Int32))
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Computes the average of a sequence of Int32 values.
Assembly: System.Core (in System.Core.dll)
'Declaration <ExtensionAttribute> _ Public Shared Function Average ( _ source As IEnumerable(Of Integer) _ ) As Double
Parameters
- source
- Type: System.Collections.Generic.IEnumerable(Of Int32)
A sequence of Int32 values to calculate the average of.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(Of Int32). When you use instance method syntax to call this method, omit the first parameter.| Exception | Condition |
|---|---|
| ArgumentNullException | source is Nothing. |
| InvalidOperationException | source contains no elements. |
The following code example demonstrates how to use Average(IEnumerable(Of Int32)) to calculate an average.
' Create a list of integers.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})
' Determine the average value in the list.
Dim avg As Double = grades.Average()
' Display the output.
outputBlock.Text &= "The average grade is " & avg & vbCrLf
' This code produces the following output:
'
' The average grade is 77.6
Show: