What is Method Hiding?

If methods are declared in a child and base class with the same signature but without the keywords virtual and override, the child class function is said to hide the base class function. The method in the child class is denoted with the New keyword.

For e.g.

public class VirtualDemo
{
    public void Hello ()
    {
        Console.WriteLine("Hello in Base Class");
    }
}

public class A : VirtualDemo
{
   public new void Hello ()
   {
      Console.WriteLine("Hello in Derived Class");
   }
}

Comments

Popular posts from this blog

jQuery Basics

What is the difference between a Page Layout and Master Page in SharePoint?

Accessing data from SharePoint 2010 to an ASP.NET application