IntroductionIn 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 StringImmutable 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 StringWe 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");