Programming Language: C# (CSharp)

Class/Type: this

Method/Function: Average

Examples at hotexamples.com: 30

Average is a function that calculates the arithmetic mean of a set of numbers. This function takes a collection of numerical values as an argument and returns the mean value of all the numbers.

Here is an example of average function:

In this example, we use the Average method provided by the Linq package library to calculate the average of the array of numbers.

Another example of using the Average function could be to find the average height of a group of people:

Here is an example of average function:

using System.Linq; double[] numbers = { 1.0, 2.0, 3.0, 4.0, 5.0 }; double average = numbers.Average();

In this example, we use the Average method provided by the Linq package library to calculate the average of the array of numbers.

Another example of using the Average function could be to find the average height of a group of people:

using System.Collections.Generic; using System.Linq; class Person { public string Name { get; set; } public double Height { get; set; } } ListIn this example, we create a list of people and use the Average method to calculate the average height of all the people in the list. The package library used in the above examples is `System.Linq`.people = new List (); people.Add(new Person { Name = "John Doe", Height = 1.8 }); people.Add(new Person { Name = "Jane Smith", Height = 1.65 }); people.Add(new Person { Name = "Bob Johnson", Height = 1.9 }); double averageHeight = people.Average(p => p.Height);

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related