相关疑难解决方法(0)

C#接口方法歧义

请考虑以下示例:

interface IBase1
{
   int Percentage { get; set; }
}

interface IBase2
{
   int Percentage { get; set; }
}

interface IAllYourBase : IBase1, IBase2
{
}

class AllYourBase : IAllYourBase
{
   int percentage;

   int Percentage {
      get { return percentage; }
      set { percentage = value; }
   }
}

void Foo()
{
   IAllYourBase iayb = new AllYourBase();
   int percentage = iayb.Percentage; // Fails to compile. Ambiguity between 'Percentage' property.
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,Percentage要调用的属性之间存在歧义.假设IBase1IBase2接口可能没有 …

c# oop interface ambiguity

31
推荐指数
6
解决办法
8166
查看次数

标签 统计

ambiguity ×1

c# ×1

interface ×1

oop ×1