Saturday, October 24, 2020

String and StringBuilder in C#

StringBuilder is used to represent a mutable string of characters. mutable means the string which can be changed. So string object are immutable but string builder is the mutable string type.

StringBuilder will not create a new modified instance of the current string object, but do the modification in the  existing string objects.

String will create a new modified instance of the current string object at time of modification in the existing string objects.

//By using string String class it create object every time when we are concinnated the string 

            string sValue = "C#";

            sValue += " Java";

            sValue += " PHP";

            sValue += " Python";

            sValue += " C";

            sValue += " C++";

            Console.WriteLine(sValue);

      //By for better performance here we should use the StringBuilder Class

            StringBuilder stringBuilder = new StringBuilder("C#");

            stringBuilder.Append("Java");

            stringBuilder.Append("C");

            stringBuilder.Append("C++");

            stringBuilder.Append("PHP");

            Console.WriteLine(stringBuilder);





 

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...