WHAT’S THE DIFFERENCE BETWEEN SYSTEM.TEXT.STRINGBUILDER AND SYSTEM.STRING?

Uttam Misra

Total Post:54

Points:270
Posted by  Uttam Misra
C# 
C#
 2788  View(s)
Ratings:
Rate this:
  1. Uttam Misra

    Post:54

    Points:270
    What’s the difference between System.Text.StringBuilder and System.String?

    StringBuilderis more efficient in the cases, where a lot of manipulation is done to thetext. Strings are immutable, so each time it’s being operated on, a newinstance is created.

  1. Amit Singh

    Post:565

    Points:2825
    What’s the difference between System.Text.StringBuilder and System.String?

    Difference between StringBuilder and string

    String and StringBuilder class stores strings. But when you cannot change a String object after creating one.
    eg: String name = "amit";
    By saying you cannot change the name object means you cannot change the value in name object internally. When you
    change the name object value to something else, a new String object is creating in memory and assign the new
    value.
    Example: name = "Amit Singh";

    If you are doing string concatenation StringBuilder class is far better in performance than String class.
    You can use StringBuilder's Append() method to use concatenation.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!