Why is the string sealed

I am curious why System.String is sealed?

I know that I can do everything I need to not inherit it, but still - why?

There are many classes that, by their nature, are strings that have specific methods and properties. These are identifiers, emails, names, etc.

Object-oriented design offers encapsulating functionality in a particular class. And here we have a strange situation when the most useful fundamental type in the most popular object structure does not expand.

Thank.

The editors.

Commentary on immutability. It's easy to hide all state-related stuff in private methods and allow child classes to have read-only access to class data.

// Safe inheritable immutable string (pseudocode).
class String
{
   // Private state
   private byte[] state;
   private void EditState(byte[]) {}
   // Protected read-only access to state
   protected byte getReadOnlyData() {}
   // Available to child classes overridable methods.
   protected virtual getHashCode() {}
   protected virtual xxx() {}
}

. , ASIN, IMEI .., , , . , - - - ..

, , , .

+4
2

, , . , , ..

, , : " ", " - " ( , , SMTP).

, String - int - ? String, System.String, , GetHashcode, , , , , , ?

@Steve, , , sealed, PoV: https://blogs.msdn.microsoft.com/ericlippert/2004/01/22/why-are-so-many-of-the-framework-classes-sealed/

, ( : , , , , , Trie, , ..), - System.String. , , String, , , , System.String (, , ..).

+11

, , CLR (, ). , CLR .

+5

All Articles