Use Average,Sum,Min and Max in LINQ query

Posted by Akiii under LINQ category on | Points: 40 | Views : 3784
Hi all,

Here, i will show how to use LINQ query to find out the Average of numbers in an array :-

Suppose, we have an array of double:-

double[] myarray = { 1.1, 2.2, 3.3 };

Now, i will use LINQ query:-

double avg= myarray.Average(); [you can use here Sum(), Min() and Max() also]

Thus, printing the value:-

Response.write("The average is {0}", avg);


The average is 2.2

Just like this we can use Sum, Min and Max function. Its pretty simple. Try it out on your own and if any problem arises, let me know.
Feel free to let me know if there is any error.
Thanks and Regards

Comments or Responses

Login to post response