المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Virtual and Override problem



C# Programming
08-24-2009, 07:30 PM
Hi,
if i have this code:
interface AInterface
{
double GetNum{ get;}
}

public class A:AInterface
{
int x;

virtual public double GetNum{
get
{
return x*10;
}
}

}

public class B:A ,AInterface
{
int y;
override public double GetNum{
get
{
return y*base.GetNum;
}
}

The problem is that if i will write this code:
B b = new B();
b.x =2;
b.y=5;
print ( B.GetNum.ToString);
I Have a problem when B call base.GetNum because it calling to him self.
What can i do to solve this problem?

Thanks for all of your help.