How to find min max and avg in an integer array using LINQ in CSharp
Sometimes we need to find the minimum, maximum and average in an array of integer. Using LINQ it become very easy to achieve this functionality.
Suppose you have an array of integer.
int[] arrInteger = new int[] { 23, 20, 17, 102, 1247, 554,32,1 };
To Find Min use the code below.
int min = arrInteger.Min();
or,
var min = (from arrInt in arrInteger
select arrInt).Min();
To Find Max use the code below.
int max = arrInteger.Max();
or,
var max = (from arrInt in arrInteger
select arrInt).Max();
To Find Average value in the array use the code below.
int avg = arrInteger.Average();
or,
var avg = (from arrInt in arrInteger
select arrInt).Average();
Enjoy Coding..................