How to find the average value in a list with C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main() {
        var list = new List<int> { 6, 8, 3, 9, 2, 4, 5 };
        
        double average_value = list.Count > 0 ? list.Average() : 0.0;

        Console.Write(average_value);
    }
}



/*
run:

5.28571428571429

*/

 



answered Mar 8, 2021 by avibootz

Related questions

1 answer 269 views
1 answer 254 views
1 answer 295 views
2 answers 189 views
1 answer 247 views
247 views asked Feb 11, 2016 by avibootz
...