locked
Rename property in a derived class RRS feed

  • Question

  •  

    Hi everyone,
    I derived a class from a Base class.
    I would change the property’s name in the derived class.
    I didn’t find as doing this.
    The starting code is:

     

    public class BaseClass

    {

        private Int16 _BaseNameProperty;

     

        public Int16 BaseNameProperty

        {

            get

            {

               return _BaseNameProperty;

            }

            set

            {

               _BaseNameProperty = value;

            } 

        }

    }

     

    public class DerivedClass: BaseClass

    {

       // DerivedNameProperty as BaseNameProperty

       public Int16 DerivedNameProperty;

       // .......

    }

     

    How can I rename (and overidde) BaseNameProperty in DerivedNameProperty?

     

    Thanks and Regards,
    Mauro


    Mauro
    Tuesday, October 14, 2008 9:08 AM

Answers

  • You can't really do that (and if you feel a need for it, maybe inheritance isn't the right choice here). What you can do is add a new property with a different name in the derived class. You can also shadow the existing property but it can still be accessed via a reference to the base class.


    Mattias, C# MVP
    Tuesday, October 14, 2008 9:13 AM