C# Program to find the average of a sequence of numeric values


Use the Linq Average() method to find the average of a sequence of numeric values.

Firstly, set a sequence.

List<int> list = new List<int> { 5, 8, 13, 35, 67 };

Now, use the Queryable Average() method to get the average.

Queryable.Average(list.AsQueryable());

Example

 Live Demo

using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
   static void Main() {
      List<int> list = new List<int> { 5, 8, 13, 35, 67 };
      double avg = Queryable.Average(list.AsQueryable());
      Console.WriteLine("Average = "+avg);
   }
}

Output

Average = 25.6

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements