I mean, I'm doing my first steps in C # and I have a doubt. I have an interface which has 4 methods, and two new classes that inherit from this interface. What I try is that when calling one of those methods "CompareTo ()" depending on whether it is an object or another to perform different tasks, the problem is that the parent class is an interface and I can not access the attribute of it since it does not It exists.
I try to follow this example, making "IComparable";
class Persona : IComparable<Persona>
{
public double Sueldo { get; set; }
public int CompareTo(Persona p)
{
return this.Sueldo.CompareTo(p.Sueldo);
}
}
class Ingeniero : Persona { .... }
class Programador : Persona { .... }
The problem is that my parent class is an interface, therefore I can not access the attribute, as I mentioned before. What would be the best way to do this? It is a silly exercise, it is not that I try to do it for pleasure: D, I see examples in Java doing casting but as I read reading is not a very advisable thing. I would like to know "professional" ways without botched by means.
Thank you very much