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

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

    Interface implementations need to be public or explicit:

    Public:

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

    Explicit:

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

    The default access modifier in C# is private if you do not specify the access modifier.

提交回复
热议问题