If there are performance gains they are likely to be insignificant. No one would implement the sealed keyword for performance reasons. You would only use it to prevent others from deriving from your class.
Using sealed keyword brings not only performance win
The article you referenced doesn't specify what kind of performance "win" there is to be had and only refers vaguely to something half-remembered by the author. One should be careful when quoting selectively from articles like that. The article completely
fails to demonstrate that there is a performance gain of any significance.
The documentation given in above URL said the following about sealed classes.
"A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes prevent derivation.
Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster."
Member
377 Points
1257 Posts
When to use a sealed class and its benefits
Sep 03, 2014 11:30 PM|sun21170|LINK
Is it a good idea to use sealed classes, and is there any benefit like performance associated with sealed classes as compared to normal class?
I know that a sealed class cannot be inherited, but why should I use it instead of a normal class?
All-Star
193986 Points
28020 Posts
Moderator
Re: When to use a sealed class and its benefits
Sep 04, 2014 01:47 AM|Mikesdotnetting|LINK
Contributor
3325 Points
403 Posts
Re: When to use a sealed class and its benefits
Sep 05, 2014 04:19 AM|Jamobor yao - MSFT|LINK
Hi,
Using sealed keyword brings not only performance win and additional code access security but also helps to write bug free code, making better use of the .NET type safety, see more at: http://www.codeproject.com/Articles/239939/Csharp-Tweaks-Why-to-use-the-sealed-keyword-on-cla
Best Regards,
Jambor
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
All-Star
193986 Points
28020 Posts
Moderator
Re: When to use a sealed class and its benefits
Sep 05, 2014 05:18 AM|Mikesdotnetting|LINK
The article you referenced doesn't specify what kind of performance "win" there is to be had and only refers vaguely to something half-remembered by the author. One should be careful when quoting selectively from articles like that. The article completely fails to demonstrate that there is a performance gain of any significance.
Member
377 Points
1257 Posts
Re: When to use a sealed class and its benefits
Sep 05, 2014 11:28 AM|sun21170|LINK
I did some research and found a mention about performance gain with sealed classes, but its not explained in detail. I came across this on MSDN at http://msdn.microsoft.com/en-us/library/ms173150.aspx.
The documentation given in above URL said the following about sealed classes.
"A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes prevent derivation. Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster."
Participant
1442 Points
2827 Posts
Re: When to use a sealed class and its benefits
Oct 20, 2014 12:39 AM|demoninside9|LINK
you should read this also
http://forums.asp.net/t/1819044.aspx?Static+class+vs+Sealed+class