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
  • 236,525
  • 50
  • 385
  • 514
Exitos
  • 29,230
  • 38
  • 123
  • 178

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
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Explicitly implemented interfaces cannot use visibility modifiers.

public List<string> IStringRepo.GetStrings() 

should be:

public List<string> GetStrings() 
x0n
  • 51,312
  • 7
  • 89
  • 111