find mean in csharp

In C#, you can find the mean or average of a set of numbers by using the Average() method from the System.Linq namespace. Here's an example:

main.cs
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] numbers = { 1, 2, 3, 4, 5 };
        double mean = numbers.Average();

        Console.WriteLine("Mean: " + mean);
    }
}
216 chars
14 lines

In this example, we have an array of integers called numbers. We then use the Average() method to find the mean or average of the numbers in the array. The result is stored in a double variable called mean. We then print out the mean using the Console.WriteLine() method.

gistlibby LogSnag