How to create a method that return the average for 5 doubles !!
How to create a method that return the average for 5 doubles !!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 9, 2012, 9:07 AM
As you may not have learned LINQ yet, I've used 'traditional' code to work out the average:
ahmed samiPosted Nov 9, 2012, 9:19 AM
you are amazing !!
ahmed samiPosted Nov 9, 2012, 7:49 AM
Shen HengbinPosted Nov 9, 2012, 12:37 AM
class Program
{
static void Main(string[] args) {
var values = new double[] { 1,2,3,4,5 };
Console.WriteLine(Average(values));
Console.Read();
}
static double Average(double[] values) {
if (values == null || values.Length == 0)
throw new ArgumentException("Parameter is null or empty");
return values.Average();
}
}