I have the following struct:-
public struct Cordination
{
public int A;
public int B;
public Cordination(int a, int b)
{
A = a;
B = b;
}
}
And then i need to calculate the distance between any two places, so i need to loop through the struct and substract the x-axis of each places and the y-axis to get the distance between any two places in the struct and then return the shortest distance; But i am not sure how i can do that :-
public float distanceInMeter(Cordination[] cordination)
{
for (i //codes goes here...)
}
Here is the answer to your question. You need to fix one coordinate and calculate distances to all others but trying not to repeat calculations. Therefore
iwill fix one coordinate andjwill iterate through all others. Note thatjis starting fromi + 1ensuring that you don’t repeat calculations.