Wednesday, February 4, 2009

C#: new modifier

Not being a C# programmer myself, it was interesting to find out that it supports a new modifier which can be used to hide a base class member in an subclass. Taking the example from the doc, consider:

public class MyBaseC 
   public int x;
   public void Invoke() {}

It is possible to have a subclass like this:

public class MyDerivedC : MyBaseC
   new public void Invoke() {}

Here MyDerivedC.Invoke hides MyBaseC.Invoke rather than override it. Pretty useful construct.

No comments: