3 回答
TA贡献1809条经验 获得超8个赞
using System;
namespace ConsoleApp
{
public class A
{
public virtual int MyFunction(int value)
{
return value + 10;
}
}
public class B : A
{
public override int MyFunction(int value)
{
int v = base.MyFunction(value)
return v + 50;
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
int v1 = a.MyFunction(100);
Console.WriteLine("A.MyFunction(100) = {0}", v1);
B b = new B();
int v2 = b.MyFunction(100);
Console.WriteLine("B.MyFunction(100) = {0}", v2);
Console.ReadKey();
}
}
}
TA贡献1818条经验 获得超11个赞
public class ClassA
{
public virtual int MyFunction(int a)
{
return a + 10;
}
}
class ClassB:ClassA
{
public override int MyFunction(int a)
{
ClassA A = new ClassA();
return A.MyFunction(a) + 50;
}
}
ClassA A = new ClassA();
ClassB B = new ClassB();
Console.WriteLine(A.MyFunction(10));
Console.WriteLine(B.MyFunction(10));
结果为20 70
添加回答
举报