Why String Is Immutable in C#?
Making String Immutable Automatically Makes Them Thread Safe Thereby Solving the Synchronization Issues. When Compiler Optimizes Your String Objects, There Are...
Making String immutable automatically makes them thread safe thereby solving the synchronization issues. When Compiler optimizes your String objects, there are two objects having same value (x="Siva", and y="Siva") and you need only one string object (for both x and y, these two will point to the same object).
Why Strings are immutable with an example?
In the String constant pool, a String object is likely to have one or many references. If several references point to same String without even knowing it, it would be bad if one of the references modified that String value. That's why String objects are immutable.
What does a String is immutable mean?
There is a term called immutable, which means the state of an object can't be changed after is has been created. A string is an immutable type. The statement that a string is immutable means that, once created, it is not altered by changing the value assigned to it.