Hiding methods in C#.Net

In this post, we will discuss hiding methods in C#.Net.

If a method with the same signature is declared in both base and derived classes but the methods are not declared as virtual and override, respectively, then the derived class version is said to hide the base class version.

Here suppose the base class method is like below:

Class Employee
{
public GetEmployee()
{
//Logic will go here
}
}

Now the derived class will be like below:

Class MyDerivedEmployee : Employee
{
public GetEmployee()
{
//Logic will go here
}
}

Now since both, the method has the same signature, then while accessing the method there will be a clash because your program won’t know which method to call.

So C#.Net generates a compile-time warning and tell us to use the new keyword while hiding a method like below:

Class MyDerivedEmployee : Employee
{
public new GetEmployee()
{
//Logic will go here
}
}

Also, you can check out:

Method Overloading in C#.Net

– Read-only textbox value lost on postback asp.net


You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply