2012-04-15 91 views
2

我一直在尝试一些n层架构,我真的想知道为什么这段代码不会编译...为什么不能公开一个实现的接口方法?

它说修饰符公共不适用于这个项目。但为什么不呢?我需要能够从BLL对象访问项目IRepository.AddString(),但它只是不会让我把它公开....

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(); 
     } 
    } 
} 

回答

0

显式实现的接口不能使用可见性修饰符。

public List<string> IStringRepo.GetStrings() 

应该是:

public List<string> GetStrings() 
相关问题