Allow field in a child class to be of a type descended from the type of the field in the parent class?

You could try generics, although it isn't pretty: abstract public class X where T : A { protected T myA; abstract public int MethodForX(); } public class Y : X { public Y() { myA = new B(); //B inherits from A } override public int MethodForX() { return myA. MethodForB(1); } } public class Z : X { public Z() { myA = new C(); //C inherits from A } override public int MethodForX() { return myA. MethodForC(1, 2); } }.

Hm... I didn't know you could specify an ancestor like that, I like it. I'll give it a shot. – Rawling Dec 18 '09 at 12:24 OK, I needed a further change: a further abstract class X containing just the abstract method, from which X inherits, so that I can still cast objects using "is X"/"as X" rather than "is X", where I didn't know what ... should be.It's getting a little more convoluted now, but still doing what I want it to from the outside.

– Rawling Dec 18 '09 at 12:35.

You could use generics. Abstract public class X where T : A { protected T myA; abstract public int MethodForX(); } public class Y : X { public Y() { myA = new B(); //B inherits from A } override public int MethodForX() { return myA. MethodForB(1); } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions