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

后端 未结 7 1432
無奈伤痛
無奈伤痛 2021-02-13 14:03

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

namespace Project.DataAccess.Interfaces
{
    public i         


        
7条回答
  •  醉梦人生
    2021-02-13 14:31

    You're not mentioning in your class declaration that you'll be implementing IAccount.

    Your class declaration should look like this:

    class Account : IAccount
    { 
      //Implementation here.
    }
    

    Also, what's happening is that you're using the "default" protection level for Account, and that protection level isn't "public", but an Interface (IAccount) defines public methods by default.

    So, when you preface both the Class and Method names with public you're actually implementing the interface. Likewise, when you declare SomeMethod as

    IAccount.SomeMethod()
    {
       //Implementation Here
    }
    

    what you're doing is Explicitly Implementing the interface.

提交回复
热议问题