Page 1 of 1

Should we make some classes and methods sealed?

Posted: Wed May 23, 2018 10:03 pm
by MeteoricDragon
I was told that making a class or method sealed in C# can offer a performance benefit. Should we make some sealed which aren't intended to be inherited from?

Re: Should we make some classes and methods sealed?

Posted: Wed May 23, 2018 10:19 pm
by Interkarma
The sealed feature is just to prevent other classes from inheriting, I don't believe it offers any tangible performance benefits.

I've heard this one before and I understand performance-wise it's no different to simply not declaring virtual methods if not required to be virtual. Heavy use of virtuals is where performance can be impacted, rather than whether a class can be inherited from or not. Otherwise it would be a rather bad language design as everything should be sealed by default.

I don't feel it's a valuable change, I'm sorry. :)