What really is the purpose of “base” keyword in c#?

后端 未结 9 1185
误落风尘
误落风尘 2020-12-08 00:42

Thus for used base class for some commom reusable methods in every page of my application...

public class BaseClass:System.Web.UI.Page
{
   public string Get         


        
9条回答
  •  半阙折子戏
    2020-12-08 01:03

    Generally, we are using the base class to reuse the property or methods in child class of the base class, so we no need to repeat the same property and methods again in the child class.

    Now, we use the base keyword to call a constructor or method from base class directly.

    Example

    public override void ParentMethod() 
      {
         base.ParentMethod(); //call the parent method
    
         //Next code.
      }
    

    2) Example

    class child: parent
    {
        public child() : base(3, 4) //if you have parameterised constructor in base class
        {
    
        }
    }
    

提交回复
热议问题