Overloading methods in interface declarations

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have an interface that contains definintions for a method with two
different signatures. For example:

namespace Paul.DemoApp
{
public interface IHello
{
void sayHello(string message, Thing myThing);

void sayHello(string message, DemoClass demo);
}
}

I then implement the interface. In Visual Studio 7, if I press TAB to create
the methods, it produces something like this:

public class HelloWorld : IHello
{
public void sayHello(string message, Thing myThing)
{
...
}

void Paul.DemoApp.IHello sayHello(string message, DemoClass demo)
{
...
}

}

The second method is created with an explicit name including the namespace.
I can 'fix' it by removing the namespace and adding the "public" access
specifer, which is what I expected to be generated in the first place.

Can anyone explain why Visual Studio generates code like the above example?

Thanks,

Paul.
 
The second method is created with an explicit name including the
namespace.
I can 'fix' it by removing the namespace and adding the "public" access
specifer, which is what I expected to be generated in the first place.

Can anyone explain why Visual Studio generates code like the above
example?


It is certainly a Bug. This also happens to me sometimes.
 
It is a bug, sort of. My colleague happened upon a blog from one of the C#
team at Microsoft which states that the implicit/ explicit behaviour was
intentional, but it causes the problem stated here now and again:

"In 2003 we attempted to intelligently choose whether to implement the
interface implicitly or explicitly. If there were existing members with the
same name but a different signature then we would implement that member
explicitly."

Read the rest of Anson Horton's article here:
http://blogs.msdn.com/ansonh/archive/2004/03/13/89185.aspx

Paul.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top