Sater
Sater

Reputation: 17

Average, Min and Max of List value

I am trying to calculate the average of radius but getting below error:

Line 136, column 30: Error - 'System.Collections.Generic.List' Average not define

Any Suggestion to fix this?

List<double> arrayRadius= new List<double>();
List<double> arrayRadiusY= new List<double>();
List<double> arrayRotation= new List<double>();
List<double> arrayPositionX = new List<double>();
List<double> arrayPositionY = new List<double>();


double AVG = arrayRadius.Average();
double Min1 = arrayRadius.Min();
double Max1 = arrayRadius.Max();
mToolBlock.Outputs["AVG"].Value = AVG;
mToolBlock.Outputs["MIN"].Value = MIN
Results;mToolBlock.Outputs["MAX"].Value = MAX;  

Upvotes: 0

Views: 1313

Answers (1)

Prasad Telkikar
Prasad Telkikar

Reputation: 16049

Average method is part of System.Linq. You need to add using directive

using System.Linq;

Try following code

List<double> radius = new List<double> { 10, 20, 30, 40, 50 };

double average = radius.Average();
double sum = radius.Sum();
Console.WriteLine("The average radius is {0}.", average);
Console.WriteLine("The sum of radius is {0}.", sum);

POC : Net fiddle

Upvotes: 2

Related Questions