开发者

Why we call always base class method like base.OnInit()

开发者 https://www.devze.com 2023-01-04 22:14 出处:网络
I am new in asp .net.I am not able to undestand why we call base class method whe开发者_如何学Pythonn we

I am new in asp .net.I am not able to undestand why we call base class method whe开发者_如何学Pythonn we override methods/events.Like automatically visual studio will put base.OnInit() if you are overriding OnInit.

  protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
    }

same is the case of Finalize. In derived we call base.Finalize()

Is there any need of calling these base class methods ?

Thanks

Ritu


Yes, if you don't put it in, then any code in the base OnInit method will not run, and you may miss something important...

Generally, you will override these methods when you want to do something additional. If you want to completely change them, then don't call the base method.


You need to call base version of the method in derived or sub class when the method of base class is over-ridden in the sub-class and you want to execute the base class version of the method in the sub-class.

0

精彩评论

暂无评论...
验证码 换一张
取 消