第1个回答 推荐于2017-10-04
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();
}
}
}本回答被提问者采纳
第2个回答 2014-10-23
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