2

I've been trying out some n-tier architecture and im really wondering why this code wont compile...

It says the modifier public is not valid for this item. But why not? I need to be able to access the item IRepository.AddString() from a BLL object but it just wont let me make it public....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            BLL myBLL = new BLL();

        }
    }

    interface IRepository<T>
    {
        void AddString();
    }

    interface IStringRepo : IRepository<string>
    {
        List<string> GetStrings();
    }

    public class BLL : IStringRepo
    {
        public List<string> FilterStrings()
        {
            return new List<string>() { "Hello", "World" };
        }

        public List<string> IStringRepo.GetStrings()
        {
            throw new NotImplementedException();
        }

        public void IRepository<string>.AddString()
        {
            throw new NotImplementedException();
        }
    }
}
svick
  • 225,720
  • 49
  • 378
  • 501
Exitos
  • 28,170
  • 37
  • 120
  • 174

2 Answers2

3

That's an explicitly-implemented member, which is always private.

Remove IStringRepo. from the declaration to create a normal public member that also implements the interface.

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933
0

Explicitly implemented interfaces cannot use visibility modifiers.

public List<string> IStringRepo.GetStrings() 

should be:

public List<string> GetStrings() 
x0n
  • 49,659
  • 7
  • 87
  • 110