Using Average Function of LINQ

This will allow you to calculate the average of numbers in the given array.
It also has the way to calculate the average of charaters in the given string array.

Sub Main()
Dim marks() As Integer = {22, 44, 12, 55}
Dim avg = marks.Average()
Console.WriteLine("The Average of the Numbers are : " & avg)

Dim names() As String = {"HEFIN", "DOTNETSPIDER", "VISUAL STUDIO"}

Dim avgwordleng = names.Average(Function(m) m.Length)
Console.WriteLine("Average Length of words in the array are :" & avgwordleng)
End Sub

Remember to
Import System.Linq
*Note : This only works in Framework 3.5
Regards Hefin Dsouza

Response if you want me to upload the sample code project.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: