I'm using List.Contains to tell whether a variable is inside the list or not, but it keeps on returning that it isn't when it is.
I've looked up MSDN and I've noticed that I have to inherit from IEquatable and implement my own .Equals method. The actual class is inheriting from another one, so I've written the .Equals method in the base class.
Here's the code of the class "Actividad":
abstract public class Actividad:IEquatable<Actividad> {
protected int codigo;
[...]
public bool Equals(Actividad otra)
{
return this.Codigo == otra.Codigo;
}
}
and here's the definition of the child class "Actividad_a":
public class Actividad_a : Actividad{ [...] }
This is the code that checks whether something is inside the list:
private void loadDisponibles() {
foreach (Actividad_a act in Program.Asignaturas) {
if (!user1.ActAcademicas.Contains(act)) {
doSomething();
}
}
}
Program.Asignaturas
and user1.ActAcademicas
are both defined as List<Actividad_a>
.
The problem is that !user1.ActAcademicas.Contains(act)
always returns true, no matter the data is in the list or not.
My first guess is that I have to inherit from IEquatable and implement .Equals method in each derived class, but I'm not really sure about it.