C# inheritance of fields

Posted by Emil D on Stack Overflow See other posts from Stack Overflow or by Emil D
Published on 2010-03-30T18:25:45Z Indexed on 2010/03/30 18:33 UTC
Read the original article Hit count: 362

Filed under:
|

This is probably a silly question, but here it goes.Imagine you have the following classes:

public class C
{
}

public class D : C
{
     //A subclass of C
}

public class A
{
    C argument;     
}

Now, I want to have a class B, that inherits from A.This class would obviously inherit the "argument" field, but I wish to force the "argument" field in B to be of type D, rather than C.Since D inherits from C this shouldn't create any problems. So, how would achieve this in c# ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about inheritance