What is meant by "strings are immutable in c#". I need some examples to understand this.I can not find some proper examples to understand this
2 Answers
Searching on your text "strings are immutable in c#" I find: http://msdn.microsoft.com/en-us/library/362314fe.aspx
Which seems to be saying that strings are never changed objects, they are always destroyed and re-created.
Per Microsoft:
Strings are immutable--the contents of a string object cannot be changed after the
object is created, although the syntax makes it appear as if you can do this.
For example, when you write this code, the compiler actually creates a new string object
to hold the new sequence of characters, and that new object is assigned to b. The string "h"
is then eligible for garbage collection.
string b = "h";
b += "ello";
string s = "bob"; s[2] = 'a'is not allowed. You cannot change a string. This is what is meant by "immutability".