Skip to content

Inheritance of class properties

Luke

Asked May 16, 2008, 3:06 PM EDT1 answer
Share
LinkedInX

I'm trying to figure out how to override the value of a propery for a parent class in a child class.

C#
For example, i have
   public class Base
   { public virtual string _Caption="parentresult";}
   public class Child
   { public override string _Caption="childresult";}

But the virtual and override keywords raise errors during compilation.  They work if i setup accessors, but I shouldn't have to do that (should I?).

Is it possible to make them consts, also?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    It shouldn't throw a compiler error if you have derived the Child from Base like

    public class Child : Base

    I don't think you can override constants.

    HTH

    0