O'Reilly logo

Start Here!™ Fundamentals of Microsoft® .NET Programming by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Shadowing Members

A member can shadow another member in a parent class if it has the same signature (name and parameters, if any). In that case, the new member supersedes the old version. This is very similar to the way a class can override a parent class member, but shadowing changes the way polymorphism works. When a member shadows another version, a variable of the parent class that refers to an object of a subclass does not use the subclass’s version of the member.

Note

Overriding is more common than shadowing.

In C#, you use the new keyword to indicate that a new version of a member shadows another. For example, consider the following Employee class:

public class Employee : Person { public string MailStop; public new void AddressEnvelope() { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required