how to change the name of property in derived class?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MaheshFarkande
    New Member
    • Jun 2012
    • 1

    how to change the name of property in derived class?

    I have base class with some properties(vari ables).I want to inherit that class and want to change name of that properties in the derived class using concept of Shadowing.Is it possible??If yes then how??

    Please help me out.
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    C# does not provide a method for giving a different name to an inherited property, as derived classes are cast-able back to the base class type. This is a fundamental feature of class inheritance, and not one you can change.

    Shadowing is when you create a property in a derived class that has the same name as one in the base class, this is sometimes used to replace the functionality of a property, but I have a feeling that if you are turning to this before answering the first issue, then you may need to look at the problem again.

    Lastly I should emphasise that properties and variables are quite different; variables hold information, where as properties act as an access gateway for information, and do not actually retain information themselves. When a property is written like this:

    Code:
    public string Name { get; set; }
    C# converts this short-cut when the program is built, into something more like this:

    Code:
    private string m_Name;
    
    public string Name 
    {
      get { return m_Name; }
      set { m_Name = value; } 
    }
    This is very relevant for understanding your question about shadowing, because understanding properties will show you weather you actually need to in the first place.

    All the best!

    Aimee Bailey.

    Comment

    Working...