I am currently trying to check if some list of mine contains an object. The list is a list of of an object which is made up of a struct which contain 2 fields.
I am trying to run this small code:
if(m_EatingMoves.Contains(i_Move))
{
....
}
But the expression will return false even though I can surely see on debug that the Move i want is inside the *m_EatingMove* list, I thought that the problem might be that I don't have an override for Equals in my struct so I found an implementation here on StackOverFlow, but the expression still returns false. Any Idea besides implementing my own Contains() ?
This is the struct:
public struct Cell
{
public int Row;
public int Col;
public Cell(int i_Row, int i_Col)
{
this.Row = i_Row;
this.Col = i_Col;
}
public override bool Equals(object obj)
{
if (!(obj is Cell))
return false;
Cell cell = (Cell)obj;
return cell.Col == Col && cell.Row == Row;
}
}
Now I have another object which is made up of the above struct:
public class Move
{
private Board.Cell m_Source;
private Board.Cell m_Destination;
public Move(Board.Cell i_Source, Board.Cell i_Destination)
{
m_Source = i_Source;
m_Destination = i_Destination;
}
....(Properties, etc..)
Finally we have the list which is initialized by the constructor
private List<Move> m_EatingMoves