Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi anyone have answer,
Using sealed Class Can We get performance Benefits?
Thanks
Akash
Posted
Updated 3-Jun-12 22:01pm
v2
Comments
Sergey Alexandrovich Kryukov 4-Jun-12 3:45am    
How this idea could come into your head?
--SA

No, not at all. There is no reason for them to offer better performance; otherwise it would mean idiotic language design with compromised performance for non-sealed classes, for no reason. And the design of C# is not idiotic at all. :-)

The purpose of the sealed classed is completely different: this is just a fool-proof feature used to prevent creation of the derived classes from the base classes not designed for this purpose — no more, no less.

—SA
 
Share this answer
 
v2
Comments
VJ Reddy 4-Jun-12 3:51am    
Nice answer. 5!
Sergey Alexandrovich Kryukov 4-Jun-12 3:58am    
Thank you, VJ.
--SA
Espen Harlinn 4-Jun-12 10:07am    
5'ed!
Sergey Alexandrovich Kryukov 4-Jun-12 12:37pm    
Thank you, Espen.
--SA
Hi,

Sealed, internal, private all this are just restrict class for visibility. this will not impact on your code performance.

Thanks
-Amit
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jun-12 4:00am    
Not exactly. "Sealed" has nothing to do with visibility. I explained what it is in my answer.
The conclusion on the impact of performance is correct.
--SA
AmitGajjar 4-Jun-12 4:09am    
you can not inherit => it means it's visibility access is limited for inheritance(wording mistake :)). if you have non-sealed class and sealed class, do you think performance will increase in case of sealed class!!!!!! No, that's what i just said.
Sergey Alexandrovich Kryukov 4-Jun-12 12:42pm    
Did you read my answer? Any my comment? I clearly stated that sealed cannot affect performance and confirmed that your conclusion is correct.
(If, by any chance, that was you who down-voted my answer because you did not understand my words, please fix it.)

By the way, I did not down-voted your answer, to give you a chance to fix it instead.
So, please fix your wording, stop confusing people. In the body of your question, tell the reader about access separately, and about limiting inheritance separately -- you understand it correctly. Anyway, I already explained things in my answer.

Thank you.
--SA
AmitGajjar 5-Jun-12 0:00am    
i never down-vote any one. because i feel that if we down-vote it will demotivate people to do more contribution. what i do is just add some comment if i feel incorrect. and even i can't down-vote your answers even in dream, bcoz your my CP role model :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jun-12 3:50am    
I voted 1 for this answer as well as for this article.
Did you read this article? Did you see the authors speculations about performance? Could you see a trivial logical flaw in those speculations?

You should only answer a question is you have your own opinion and sure about it. Otherwise, not answering is way more useful. Please remember that such answer may cost too much wasted time for an inexperienced inquirer; be responsible.

--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900