Tuesday, July 26, 2011

My Leading Candidate for Worst C# Feature – Method Hiding

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: My_2D00_Leading_2D00_Candidate_2D00_for_2D00_Worst_2D00_C_2D00_Feature_2D00_e28093_2D00_Method_2D00_Hiding.aspx

Posted via email from Jasper-Net