Wednesday, July 20, 2016

Shadowing in c#

Shadowing in c#


new keyword explicitly hides member that is inherited from the base class (base class method is hidden or we can say derived class replaces/hides the base method) 

When you hide an inherited member, the derived version of the member replaces the base class version.


* It is an error to use both new and override on the same member, because the two modifier have mutually exclusive meanings. The new modifier creates a new member with the same name and causes the original member to become hidden. The override modifier extends the implementation for an inherited member.

public class BaseC
{
public int x;
public void invoke()
{
}
}

public class DerivedC : BaseC
{
   nenw public void Invoke()
   {
    }
}

No comments:

Post a Comment