Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this overridden method grayified?

In the code I have to maintain ("Lucky Man" by ELP definitely does not fit this soundtrack), I see this, grayed out (not commented out -- grayed out by the compiler or Resharper):

protected override void Dispose( bool disposing )
{
    base.Dispose( disposing );
}

An orange light bulb glyph (Resharper?) msg says about it, "Remove redundant method override"

A skyblue circular glyph with a "0" inside says:

"Overrides method from class 'System.ComponentModel.Component" -and: "Overrides method from class 'System.Windows.Forms.Control"

I take it what it is saying is that this override does nothing beyond what the method it's overriding does, and thus I can remove it entirely. Am I right?

like image 871
B. Clay Shannon-B. Crow Raven Avatar asked Apr 26 '26 10:04

B. Clay Shannon-B. Crow Raven


2 Answers

Since you're just calling the base method, there's no reason for that code to be there, hence it can be removed.

like image 160
Kenneth Avatar answered Apr 27 '26 22:04

Kenneth


I realize that this is an old question but just wanted to add a tiny detail here. If you derive another class from your derived class you will not be able to call base.Dispose from that one unless you keep the "redundant" function.

like image 28
thehan83 Avatar answered Apr 28 '26 00:04

thehan83



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!