i read some articles but most of them are abstracted and i can't get answering of my questions. i know the difference between Abstract and Sealed Classes.but when my instructor explained the difference he said in c# when you want to make some developers to follow your design you need to use Abstract class and this give some safety of your code and gave examples and i understand what he means but when he explained sealed class he said we can't inherit from string class because it's sealed class. so that's using of sealed classes and didn't give the reason.
Asked
Active
Viewed 186 times
0
-
Supppose you have a class that you want to prevent to be inheritable. In that case you set your class as `sealed`. Why you don't want to be inheritable? that's up to you. – Gusman Jun 13 '20 at 14:36
-
i know this but what i mean is why specifically is sealed string class ? and to be more clearly what if string class is not sealed How can affected ? – Muhamed Taha Jun 13 '20 at 14:49
-
1Duplicate of [Why string is sealed](https://stackoverflow.com/questions/35951430/why-string-is-sealed). See also the documentation of [`sealed`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/sealed) and [`abstract`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/abstract). – 41686d6564 stands w. Palestine Aug 23 '20 at 20:31
1 Answers
3
A sufficient reason why String is sealed is that String is a performance-critical class because most programs use it heavily. And so it's heavily optimized. Virtual method calls have some additional overhead, as it must be determined at runtime which method to actually call, the base-type method, or some override.

David Browne - Microsoft
- 80,331
- 6
- 39
- 67