【发布时间】:2012-04-27 05:00:43
【问题描述】:
可能重复:
Why Explicit Implementation of a Interface can not be public?
I read this Question。直接从问题开始
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();
}
}
为什么公开明确引用的成员是Error?
【问题讨论】:
-
您希望
public修饰符做什么?你可以(至少从普通的 C# 代码)只能通过接口调用这个方法,因为它没有普通的方法名。 -
因为语言规范是这么说的。
-
如果你能做出显式接口实现
public,那普通(隐式)接口实现有什么区别?