Solved

# Max, Min and Average of a selection of Cells in Array 2D on C#?

Posted on 2011-10-19
Medium Priority
370 Views
On C#.
If int myArray [310,220];
How to know the Max, Min and Average of a selection of cells?
Example:
int myArrayMax = FROM HERE myArray[55,10] TO HERE myArray[250,200];
int myArrayMin  = FROM HERE myArray[55,10] TO HERE myArray[250,200];
double myArrayAverage = FROM HERE myArray[55,10] TO HERE myArray[250,200];

Thank you,
ocaccy
0
Question by:ocaccy
• 3
• 2

LVL 17

Expert Comment

ID: 36997976
Using linq you can find it easily

nt myArrayMax = myArray.Max()
nt myArrayMax = myArray.Min()
nt myArrayMax = myArray.Avg()

http://www.java2s.com/Code/CSharp/LINQ/Maxonintarray.htm
0

Author Comment

ID: 36998874
Thank you. Very good information.

However, I still need to know how to make the Average, Min, Max and Sum on a 2D array, and the same thing in a selection of cells, not the entire array.

Thank you very much,
ocaccy

``````int myArrayMax = FROM HERE myArray[55,10] TO HERE myArray[250,200];
int myArrayMin  = FROM HERE myArray[55,10] TO HERE myArray[250,200];
double myArrayAverage = FROM HERE myArray[55,10] TO HERE myArray[250,200];
``````
0

LVL 37

Expert Comment

ID: 37006810
This question was answered here http:Q_27408102.html#37004473
0

Author Comment

ID: 37021330
TommySzalapski, wrote this:

int max(int[,] array, int first_col, int last_col, int first_row, int last_row)

However, I need for loop for this too.
In C#.

for loop running like this:

myArray2[0,0] = maximun from here - myArray1[1,0] to here myArray1[3,0];
myArray2[1,0] = average from here - myArray1[4,0] to here myArray1[6,0];

i need a for loop, because it will be so in all 60 columns in myArray1 with myArray2.

Regards,
ocaccy
Array-For-loop.png
0

LVL 37

Accepted Solution

TommySzalapski earned 2000 total points
ID: 37025003
So you need something like this (using the functions we built in the other question).
``````for(int i = 0; i < 60; ++i)
{
myArray2[0][i] = max(myArray1(1, 3, i, i);
myArray2[1][i] = average(myArray1(4, 6, i, i);
}
``````
0

Author Closing Comment

ID: 37028308
Thank you Tommy.

You have helped me a lot in the arrays.

Best Regards,
ocaccy
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't know how to downgrade, my instructions below should be helpful.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
###### Suggested Courses
Course of the Month14 days, 14 hours left to enroll