I have:
I:
public interface I
{
void Something();
}
A:
public class A : I
{
public void Something()
{
}
}
B:
public class B : A
{
}
Why isn’t B forced to implement (the decired) Something method, as expected?
Do I really have to inheried I on all my B’s(subclasses to A)?
public class B : A, I
{
public void Something()
{
}
}
B isn’t forced to implement I, because it’s already implemented in A.
If you want to force B to implement it, you have to make it abstract in A, or not implement the interface on A, only implement I in B.
On a different note, if you want to allow B to override the method defined in A, you should make the method virtual in A, and then use the override keyword to override the method in B. Right now your Something method is not virtual in A, so if you try to override it in B, the compiler will either give you and error or a warning stating that you are “hiding” the method Something in a base class.