Should we make some classes and methods sealed?

Discuss coding questions, pull requests, and implementation details.
Post Reply
User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Should we make some classes and methods sealed?

Post by MeteoricDragon » Wed May 23, 2018 10:03 pm

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?

User avatar
Interkarma
Posts: 5188
Joined: Sun Mar 22, 2015 1:51 am

Re: Should we make some classes and methods sealed?

Post by Interkarma » Wed May 23, 2018 10:19 pm

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. :)

Post Reply