Compiler says I am not implementing my interface, but I am?

Viewed 12474

Okay, I have two namespaces. One contains my interface and one contains the implementing class. Like this:

namespace Project.DataAccess.Interfaces
{
    public interface IAccount
    {
        string SomeMethod();
    }
}

namespace Project.DataAccess.Concrete
{
    class Account : Project.DataAccess.Interfaces.IAccount
    {
        string SomeMethod()
        {
            return "Test";
        }
    }
}

With this code I get an error:

'Project.DataAccess.Concrete.Account' does not implement interface member 'Project.DataAccess.Interfaces.IAccount.SomeMethod'. 'Project.DataAccess.Concrete.Account.SomeMethod' cannot implement an interface member because it is not public

If I make the class and method public it works fine. But if I instead qualify the method name with the interface name, that fixes it too. Why? Ex:

namespace Project.DataAccess.Concrete
{
    class Account : Project.DataAccess.Interfaces.IAccount
    {
        string IAccount.SomeMethod()
        {
            return "Test";
        }
    }
}

Why does this fix it? And why does it have to be public if I don't do that?

To be clear

I am well aware that making it public fixes it. Making the method signature look like this WITHOUT making anything public fixes it:

string IAccount.SomeMethod()

Why?

7 Answers
Related