Tuesday, April 24, 2012

Differnce between new and override

It is asked very frequently, that how can we call the parent version of a method in inheritance. In C# we can use new keyword to define a new method in child class and get this effect. I have mentioned a little example that will illustrate you the difference between override and new keyword :


//Calls Base class function 1 as new keyword is used.

BaseClass bd = new DeriveClass();

bd. function ();



//Calls Derived class function 2 as override keyword is used.

BaseClass bd2 = new DeriveClass();

bd2. function ();




Thank You. Happy coding....
Earn Money ! Affiliate Program
Open Directory Project at dmoz.org