Creating Extension methods with same name as instance methods

I had a really good time at the user group meeting tonight. Learned some new stuff on linq. An interesting point one of my prior co-worker Matt mentioned was if you create an extension method with the same name as the instance level method on the class, the compiler does not raise any exceptions. For a second I didn't believe it and so I went home and tried. Sure enough he was true. I would think that it is illegal to declare an extension method with the same name as instance method because instance method should always take precedence over extension method. Also say if you had an extension method that does some stuff. Later you upgrade to a new framework and the framework also includes a method with the same name. Since C# compiler does not raise compilation error, you wouldn't know that in fact you are actually using the method implementation from the framework than your extension method which may not be the desired behavior. I am curious to know why other people think that C# compiler should not raise a compilation error in this scenario.

No Comments