C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




SubclassName.MethodName’ Hides Inherited Member ‘BaseclassName. MethodName’. Use the New Keyword if


Posted Date: 28 Sep 2008    Resource Type: Errors and Solutions    Category: General
Author: Bindu BujjiMember Level: Gold    
Rating: Points: 5



SubclassName.MethodName’ Hides Inherited Member ‘BaseclassName. MethodName’. Use the New Keyword if Hiding was Intended Error:

Let's loook at the following example:
=====================================

public class BaseClass
{
public void Method() \\ base-class version.
{
}
}
public class SubClass : BaseClass
{
public void Method() \\ Here's the overload.
{
}
}
public class MyClass
{
public void Test()
{
SubClass sb = new SubClass();
sb.Method();
}
}


The method Test() cannot get at the method BaseClass.Method() from the subclass object sb because it is hidden by SubClass.Method().
You intended to do one of the following:

You intended to hide the base class method. In that case, add the new keyword to the SubClass definition, like below

public class SubClass : BaseClass
{
new public void Method()
{
}
}

You meant to inherit the base class polymorphically, in which case you should have declared the two classes as follows:


public class BaseClass
{
public virtual void Method()
{
}
}
public class SubClass : BaseClass
{
public override void Method()
{
}
}

NOTE:
=====
This is not an Error, just a Warning in the Errorwindow.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
SubclassName.MethodName’ Hides Inherited Member ‘BaseclassName. MethodName’.  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Unable to Copy the File ‘ProgramName.exe’ to ‘programName.exe’. The Process Cannot …
Previous Resource: Multi Part Identifier "[Tablename].[Columnname]" Could not be bound
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use