I love C#, I really do. Of course is has its little annoying quirks here and there, but in general it is, IMHO, one of the best static programming languages out there. Having said that, one thing that makes me wonder “WHAT THE HELL WERE THEY THINKNING?!?$?!?” every single time is the feature known as “Method Hiding”.
What is Method Hiding?Method hiding, in short, is the crippled, mentally-ill brother of method overriding. For example, look at the next code:class A
{
public string GetName()
{
return "A";
}
}class B : A
{
public new string GetName()
{
return "B";
}
}Class A has a GetName method; class B inherits from class A and implements the GetName method as well.
Look carefully at the GetName method signature in class B – do you see the new keyword there? this means that the method doesn’t override the implementation in class A, it just hides it. What does that mean? read on.
So What’s the Big Deal? Hide, Override… Who Cares?
Read more: IronShay
QR:
What is Method Hiding?Method hiding, in short, is the crippled, mentally-ill brother of method overriding. For example, look at the next code:class A
{
public string GetName()
{
return "A";
}
}class B : A
{
public new string GetName()
{
return "B";
}
}Class A has a GetName method; class B inherits from class A and implements the GetName method as well.
Look carefully at the GetName method signature in class B – do you see the new keyword there? this means that the method doesn’t override the implementation in class A, it just hides it. What does that mean? read on.
So What’s the Big Deal? Hide, Override… Who Cares?
Read more: IronShay
QR:
0 comments:
Post a Comment