P
Peter K
Hi
I have a class A which implements interface IUserDal, which has several
public methods. None of these methods are declared
virtual.
public class A : IUserDal
There is also a client C, which uses A (but only knows A via the interface
IUserDal).
Now I want to extend A with class B - where I want to change/override only
one of the methods - GetUsername().
public class B : A
(and in class B I declare a new method "GetUsername()").
I can't really "override" the method, but I can "hide" it. The strange thing
is (at least to me) that with the above definitions, the client C still
calls the GetUsername method in the A class.
For example:
IUserDal dal = new B();
string s = dal.GetUsername();
will actually call the method in class A.
However, if I change B, so it looks like:
public class B : A, IUserDal
then the GetUsername method in B is called.
Why is this?
Thanks,
Peter
I have a class A which implements interface IUserDal, which has several
public methods. None of these methods are declared
virtual.
public class A : IUserDal
There is also a client C, which uses A (but only knows A via the interface
IUserDal).
Now I want to extend A with class B - where I want to change/override only
one of the methods - GetUsername().
public class B : A
(and in class B I declare a new method "GetUsername()").
I can't really "override" the method, but I can "hide" it. The strange thing
is (at least to me) that with the above definitions, the client C still
calls the GetUsername method in the A class.
For example:
IUserDal dal = new B();
string s = dal.GetUsername();
will actually call the method in class A.
However, if I change B, so it looks like:
public class B : A, IUserDal
then the GetUsername method in B is called.
Why is this?
Thanks,
Peter