Hi Alan,
basically what the compiler is telling you that a method in your derived
class is hiding a method in the base class. It is possible you want to do
this, if so you want to add the new keyword to the method signature in the
derived class which explicitly states you know you are hiding a method and
intended to do so. So for example:
class Person
{
public string Description()
{
return "I am a person";
}
}
class Man : Person
{
public string Description()
{
return "I am a man";
}
}
class Program
{
static void Main(string[] args)
{
Man m = new Man();
//Outputs "I am a man"
Console.Out.WriteLine(m.Description());
Person p = m;
//Outputs "I am a person"
Console.Out.WriteLine(p.Description());
}
}
The method called on the variable is defined by it's runtime type, so you
can see the description method in the Man class hides the implementation in
the base Person class when accessing it with a reference of type man. If you
want to get rid of the compiler warning you can use the new keyword i.e.:
public new string Description()
If you want to actually change the implementation of the method in the
derived class then you need to make the method virtual in the base class and
then override the method in the derived class.
Mark.
--
http://www.markdawson.org
"Alan T" wrote:
I got a method in my ancestor form declared as Protected, this method has
empty body.
In my descendant form I declared as Protected also, then compile has no
problem but the name of the method has green underline.
The warning of the compilation is about the method hides inherited member.
Use the new keyword if hiding was intened.