Extending abstract classes in c#
- by ng
I am a Java developer and I have noticed some differences in extending abstract classes in c# as opposed to Java. I was wondering how a c# developer would achived the following.
1) Covarience
public abstract class A {
public abstract List<B> List();
}
public class BList : List<T> where T : B {
}
public abstract class C : A {
public abstract BList List();
}
So in the above hierarchy, there is covarience in C where it returns a type compatible with what A returns. However this gives me an error in Visual Studio. Is there a way to specify a covarient return type in c#?
2) Adding a setter to a property
public abstract class A {
public abstract String Name { get; }
}
public abstract class B : A {
public abstract String Name { get; set }
}
Here the compiler complains of hiding. Any suggestions?
Please do not suggest using interfaces unless that is the ONLY way to do this.