using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Learn { class Program { static void Main(string[] args) { // Reference B through A. A ab = new B(); ab.Y(); // Reference C through A. A ac = new C(); ac.Y(); Console.Read(); } } class A { public virtual void Y() { // Used when C is referenced through A. Console.WriteLine("A.Y"); } } class B : A { public override void Y() { // Used when B is referenced through A. Console.WriteLine("B.Y"); } } class C : A { new public void Y() //public void Y() // Can be "new public void Y()" { // Not used when C is referenced through A. Console.WriteLine("C.Y"); } } }
A ac = new C();
C ac = new C();
((C)ac).Y();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)