I am trying to print the coordinates if my object is found in the 2D array. Am using .Equals but it seems to be ignoring it.
private void PrintCarInfo(Car car, object[,] matrix)
{
int xCoordinate = 0;
int yCoordinate = 0;
int w = matrix.GetLength(0);
int h = matrix.GetLength(1);
for (int x = 0; x < w; ++x)
{
for (int y = 0; y < h; ++y)
{
if (matrix[x, y].Equals(car))
{
xCoordinate = x;
yCoordinate = y;
}
}
}
}
This is the Car class:
public class Car
{
public int Index { get; set; }
public string Name { get; set; }
public bool Manual { get; set; }
public bool Diesel { get; set; }
public Car()
{
}
public Car(Car car)
{
Index = car.Index;
Name = car.Name;
Manual = car.Manual;
Diesel = car.Diesel;
}
}
This is what I get when debug from the 2D array:
[1,1] {Toyota (15)}