Introduction
In this article, I am explaining about OOPS component what is the difference between a mutable and immutable string in C#. I have explained with example about difference between a mutable and immutable string. Moreover, already explained about What is Boxing and Unboxing in C# in my earlier article. Here is showing another example of OOPS.Immutable String
Immutable string can’t be alter, once we have given a value to immutable object state can’t be changed. We can use System.String to use immutable string.String str = “Technology Crowds”; //* Immutable String Example string str = “Technology Crowds” + “Technology”;
Mutable String
We can assign multiple values to changeable string and object state will be altered. Best example of changeable is stringbuilder object will be used. we will multiple concatenation to changeable string. changeable have superb flexibility to alter object state, changeable string will generate long string.We can use given below namespace to use mutable string in c#
using System.Text; //* namespace used to import string builder StringBuilder strLong = null; //* [Mutable String] example strLong.Append("Technology"); strLong.Append("Crowds");
I have demonstrated with my best about what is the difference between a mutable and immutable string in C# that can help you better understand difference between a mutable and immutable string.
Mutable: Mutable means whose state can be changed after it is created.
ReplyDeleteImmutable: Immutable means whose state cannot be changed once it is created.
String objects are 'immutable' it means we cannot modify the characters contained in string also operation on string produce a modified version rather than modifying characters of string.
Use Reference
imaginationhunt.blogspot
IS STRING MUTABLE OR IMMUTABLE IN .NET?
http://imaginationhunt.blogspot.in/2015/06/is-string-mutable-or-immutable-in-net.html