You must Sign In to post a response.
- Category: .NET
- #172436String is immutable
i.e. Strings cannot be altered. When you alter a string (by adding to it for example), you are actually creating a new string.
But StringBuilder is not immutable
so if u have to alter a string many times, such as mutliple concatenations then use StringBuilder.
- #172437An object qualifies as being called immutable if its value cannot be modified once it has been created. For example, methods that appear to modify a String actually return a new String containing the modification. Developers are modifying strings all the time in their code. This may appear to the developer as mutable - but it is not. What actually happens is your string variable/object has been changed to reference a new string value containing the results of your new string value. For this very reason .NET has the System.Text.StringBuilder class. If you find it necessary to modify the actual contents of a string-like object heavily, such as in a for or foreach loop, use the System.Text.StringBuilder class.
MVP SQL Server
immutable means data value may not be changed but mutable means data value will be changed.
thanks and regards,
- #278671• Mutable & Immutable
System.StringBuilder is mutable where variety of operations can be performed
System.String is immutable variable value may change BUT original data value will be discarded and new value will be in memory.
- #304413Simply says
Mutable is liable to change
Immutable is not liable to change...