First look at the following code:
Using System;namespace test{public class base{public void Print () {Console.WriteLine (Operate (8, 4));} protected virtual int Operate (int x, int y) {return x + y;}}}
Namespace Test{public class oncechild:base{protected override int Operate (int x, int y) {return x-y;}}
Namespace Test{public class twicechild:oncechild{protected override int Operate (int x, int y) {return x * y;}}
namespace Test{public class thirdchild:twicechild{}}
Namespace Test{public class forthchild:thirdchild{protected new int Operate (int x, int y) {return x/y;}}}
namespace Test{class program{static void Main (string[] args) {Base b = null;b = new Base (); B.print (); b = new Oncechild (); b. Print (); b = new Twicechild (); B.print (); b = new Thirdchild (); B.print (); b = new Forthchild (); B.print ();}}}
Look at the results:
As can be seen from the results: after using override rewrite, the function called is the furthest derived function, using the new override is to call new before the derivation of the furthest function, that is, the new as no rewrite.
function calls in C # inheritance