Introduction:

In this article we will learn, how to use LINQ Average() Function or what is LINQ Average() Function C# Asp.net Mvc with example.

Description:

In LINQ, The Average() Function gives us the average of the elements from a collection or List. It is use to computes average value of numeric collection. LINQ has made it very easy to computes average value of numeric collection.

 

LINQ Count() Function Example

Now we will see the example of using LINQ Average() function to calculate average of items in collection / list.

 
 using System;
using System.Collections.Generic;
using System.Linq;
namespace SQLTutorialsPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Num = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            Console.WriteLine("Find the average of the elements:");
            double Average = Num.Average();
            Console.WriteLine("The Average is {0}", Average);
            Console.ReadLine();
        }
    }
}

 

 When we execute above c# program, we will get the result like as shown below.

 how to use Average function in linq c#

As you see above example we have a integer array “Num” and we will get average of the elements in given array using LINQ Average() function.

 

I hope it will help to you after reading.

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like