Saturday 22 March 2014

how to access base class method in derived class in c#

By using the Base key word you can use the base class method into the derived class;
// base class
    public class BaseClass
    {
        protected virtual void GetValue()
        {
            // Write the code stuff
        }
    }
    // derived class
    public class DerivedClass : BaseClass
    {
        protected  override void GetValue()
        {
            base.GetValue();//CCalling the base class method
            DoGetOtherValue();
        }
        private void DoGetOtherValue()
        {
            //perform other operations
        }
     
    }

No comments:

Post a Comment