显式实现还用于解决两个接口分别声明具有相同名称的不同成员(如属性和方法)的情况:

interface ILeft
{
    int P { get;}
}
interface IRight
{
    int P();
}

为了同时实现两个接口,类必须对属性 P 和/或方法 P 使用显式实现以避免编译器错误。例如:

显式接口
class Middle : ILeft, IRight
{
    public int P() { return 0; }
    int ILeft.P { get { return 0; } }
}

相关文章:

  • 2021-10-21
  • 2021-08-01
  • 2022-12-23
  • 2021-12-28
  • 2021-12-27
  • 2021-12-05
  • 2021-11-29
  • 2021-12-05
猜你喜欢
  • 2021-06-15
  • 2022-12-23
  • 2021-10-16
  • 2022-01-15
  • 2021-12-20
相关资源
相似解决方案