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

后端 未结 7 1444
無奈伤痛
無奈伤痛 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:22

    class Account : IAccount    
        {         
        public string SomeMethod()         
        {            
         return "Test";         
        }     
        } 
    

    Tell your class to implement the interface. Using the Interface.Method name explicitly implements the method (but i'm not sure why or how) and you need to make them public.

    You want to use Interface.Method to explicitly implement an interface requirement when the class already has a member of the same name

    class MyClass : IAccount
    {
       public int SomeMethod() {}
       public string IAccount.SomeMethod() {}
    }
    

提交回复
热议问题