Search this blog

Sunday, June 7, 2009

String Vs StringBuilder

The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new String object can be costly.

The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. For example, using the StringBuilder class can boost performance when concatenating many strings together in a loop.

4 comments:

  1. Thanks for comments and i voted you

    ReplyDelete
  2. But it has been shown that String.Concat with up to 4 parameters is actually faster than StringBuilder.

    ReplyDelete
  3. Hi,

    Thanks for the comments.

    if u look at the internal usage of String.Concat, every time of access, it is creating on new memory location.

    ReplyDelete
  4. hi could you please answer
    if i am comparing two datetimepicker control value from the third one
    and if i choose the condision where the third value is less then from first
    and greater than from second

    so the problem is that if i compare this way and i choose the condition where all three datetime are equal so it should fall in my condision but it's behaviour is very different...Please reply i would be very thank full you..

    ReplyDelete