本文介绍了接口模棱两可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class CustomCllection
{
C c1 = new XYZ();
A a1 = new XYZ();
B b1 = new XYZ();
XYZ x = new XYZ();
public void Check()
{
a1.i = 30;
a1.Test1();
a1.Test2();
//-----------
b1.k = 30;
b1.Test2();
b1.Test3();
//----------------
c1.i = 40;
c1.k = 50;
c1.m = 60;
c1.Test1();
c1.Test2(); // [Edit]Error is here
c1.Test3();
c1.Test4();
}
}
interface A
{
void Test1();
void Test2();
int i { get;set;}
}
interface B
{
void Test2();
void Test3();
int k { get;set;}
}
interface C : B, A
{
new void Test3();
void Test4();
int m { get;set;}
}
class XYZ : C
{
public void Test1()
{
MessageBox.Show("Hello I am Test1");
}
void A.Test2()
{
MessageBox.Show("Hello I am Test2(A)");
}
void B.Test2()
{
MessageBox.Show("Hello I am Test2(B)");
}
public void Test3()
{
MessageBox.Show("Hello I am Test3");
}
public void Test4()
{
MessageBox.Show("Hello I am Test4");
}
int nn = 10;
public int i
{
set { value = nn; }
get { return nn; }
}
int nm = 10;
public int m
{
set { value = nm; }
get { return nm; }
}
int km = 10;
public int k
{
set { value = km; }
get { return km; }
}
}
给我们错误:
错误1以下方法或属性之间的调用是模棱两可的. A.Test2()和B.Test2()
任何人都可以解释为什么会发生这种模棱两可的情况.
由DaveyM69添加.
Give Us Error:
Error1The call is ambiguous between the following methods or properties. A.Test2() and B.Test2()
Can Any One Explain Why this ambiguous Occur.
Added by DaveyM69
推荐答案
这篇关于接口模棱两可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!