Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

StringMutability

In C#, strings are immutable, and const fields may not be modified.

But can we change the value of a const string anyways?

Conclusion

Yes, we can get a read-write Span<char> from the string, and use it to modify the content of the string.

If we rely on string interning, we can even change the content of a string without directly referring to it, by modifying the content of a different interned string with the same content.

This approach does however come with the limitation that the length of the string cannot be expanded.