Ad
  • Custom User Avatar

    Speed is not the reason of the necessity to use StringBuilder, it is a consequence.
    When you concat 2 string, the system need to create a new array for the new string and copy all the bytes

    So, your program will take twice the memory for the operation and copy again and again all the bytes to the new string.

    StringBuilder use a bigger array and increased it's size when the limit is reach (like 2,4,8,16,32, ... x2 each times).

    Each Append() copy only the bytes of the given string and do array resize time to times when size limit is reached, not each time.

  • Default User Avatar

    I didn't know ternary operators can be used in such ways! Mind. Blown.

  • Default User Avatar