Reputation: 2454
double[] tab = new double[10];
I know I can gen minimum by tab.Min()
.
double[,] tab = new double[10,2];
This is table of coordinates, in 2nd index 0 is x and 1 is y. There are 10 points.
How can I get minimum (and maximum) value of x and y?
In other words:
minX
is the smallest value in 1st column (second index=0 e.g tab[xxx, 0]
);
minY
is the smallest value in 2nd column (second index=1 e.g tab[xxx, 1]
);
Upvotes: 6
Views: 10190
Reputation: 613
double minX = tab[0,0], minY = tab[0,1];
String coordinate = "X";
foreach (double number in tab)
{
if (coordinate == "X")
{
if(number < minX)
minX = number;
coordinate = "Y";
}
else if (coordinate == "Y")
{
if (number < minY)
minY = number;
coordinate = "X";
}
}
Upvotes: 0
Reputation: 14874
var doubles = new double[4,2]{{1,2},{4,5},{7,8},{9,1}};
var min = System.Linq.Enumerable.Range(0, 4).Select(i => doubles[i, 1]).Min();
OR
var doubles = new double[4,2]{{1,2},{4,5},{7,8},{9,1}};
var min = System.Linq.Enumerable.Range(0, doubles.GetUpperBound(0)+1)
.Select(i => doubles[i, 1]).Min();
Upvotes: 7