我有一个界面:
public interface Profile
{
string Name { get; }
string Alias { get; set; }
}
所有实现的对象Profile都有 aName和 an Alias,但有些限制Alias使其始终与Name. 应用此限制的可以Alias这样实现:
string Profile.Alias
{
get
{
return ((Profile)this).Name;
}
set { }
}
由于this在显式接口实现的上下文中只能是类型Profile,并且我们知道它是通过Profile接口而不是包含类或它实现的任何其他接口访问的,为什么需要强制转换?
使用return this.Name;getter 实现会导致此错误:
Type `ConcreteProfile' does not contain a definition for `Name' and no extension method `Name' of type `ConcreteProfile' could be found (are you missing a using directive or an assembly reference?)