I have following code:
public abstract class TestProperty
{
public abstract Object PropertyValue { get; set; }
}
public class StringProperty: TestProperty
{
public override string PropertyValue {get;set}
}
which generate compilation error, I wonder should I have to use generic type in TestProperty in order to achive my goal of having different type of the same name in the child class?
Yes, C# doesn’t support covariant return types. You can indeed use generics here:
There’s no need to override at this point – and indeed unless you’re going to do anything else, you might as well get rid of
StringPropertyentirely and just useTestProperty<string>.