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");

Mutable vs Immutable
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.

Conclusion

All string object are immutable in C#, String builder would allow us to work alternatively like as Mutable string in C#.

Best ASP.Net (C#) Comparisons: