Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, <a href="http://msdn.microsoft.com/en-us/library/system.string.aspx" rel="nofollow"><code>String</code></a> and <a href="http://msdn.microsoft.com/en-us/library/System.Text.StringBuilder%28v=vs.110%29.aspx" rel="nofollow"><code>StringBuilder</code></a> are different classes.</p> <p><code>String</code> class represents <a href="http://en.wikipedia.org/wiki/Immutable_object" rel="nofollow"><em>immutable types</em></a> but <code>StringBuilder</code> class represent mutable types.</p> <p>When you use <a href="http://msdn.microsoft.com/en-us/library/vstudio/k1a63xkz%28v=vs.110%29.aspx" rel="nofollow"><code>+</code></a> to concatanate your strings, it uses <a href="http://msdn.microsoft.com/en-us/library/system.string.concat%28v=vs.110%29.aspx" rel="nofollow"><code>String.Concat</code></a> method. And every time, it returns a new string object.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.append%28v=vs.110%29.aspx" rel="nofollow"><code>StringBuilder.Append</code></a> method appends a <em>copy</em> of the specified string. It doesn't return a new string, it changes the original one.</p> <p>For efficient part, you should read Jeff's article called <a href="http://www.codinghorror.com/blog/2009/01/the-sad-tragedy-of-micro-optimization-theater.html" rel="nofollow"><code>The Sad Tragedy of Micro-Optimization Theater</code></a></p> <blockquote> <p><strong>It. Just. Doesn't. Matter!</strong></p> <p>We already know none of these operations will be performed in a loop, so we can rule out brutally poor performance characteristics of naive string concatenation. All that's left is micro-optimization, and the minute you begin worrying about tiny little optimizations, you've already gone down the wrong path.</p> <p>Oh, you don't believe me? Sadly, I didn't believe it myself, which is why I got drawn into this in the first place. Here are my results -- for 100,000 iterations, on a dual core 3.5 GHz Core 2 Duo.</p> </blockquote> <pre><code>1: Simple Concatenation 606 ms 2: String.Format 665 ms 3: string.Concat 587 ms 4: String.Replace 979 ms 5: StringBuilder 588 ms </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload