Similar illustration with virtual properties. | Lecture 7 - slide 40 : 40 Program 2 |
using System; public class A{ public int v = 1; public virtual int V{ get{ return v;} } } public class B: A{ public new int v = 5; public override int V{ get{ return v;} } } public class App{ public static void Main(){ // Static type Dynamic type A anA = new A(), // A A anotherA = new B(); // A B B aB = new B(); // B B Console.WriteLine( "{0}", // Variable access Property Access anA.V // 1 1 + anotherA.V // 1 5 + ((B)anotherA).V // 5 5 + aB.V // 5 5 ); } } |