title: Tips for optimizing C#/.NET programs
body: <p>It seems like optimization is a lost art these days. Wasn't there a time when all programmers squeezed every ounce of efficiency from their code? Often doing so while walking five miles in the snow?</p>
  
  <p>In the spirit of bringing back a lost art, what are some tips that you know of for simple (or perhaps complex) changes to optimize C#/.NET code? Since it's such a broad thing that depends on what one is trying to accomplish it'd help to provide context with your tip. For instance:</p>
  
  <ul>
  <li>When concatenating many strings together use <code>StringBuilder</code> instead. See link at the bottom for caveats on this.</li>
  <li>Use <code>string.Compare</code> to compare two strings instead of doing something like <code>string1.ToLower() == string2.ToLower()</code></li>
  </ul>
  
  <p>The general consensus so far seems to be measuring is key. This kind of misses the point: measuring doesn't tell you what's wrong, or what to do about it if you run into a bottleneck. I ran into the string concatenation bottleneck once and had no idea what to do about it, so these tips are useful.</p>
  
  <p>My point for even posting this is to have a place for common bottlenecks and how they can be avoided before even running into them. It's not even necessarily about plug and play code that anyone should blindly follow, but more about gaining an understanding that performance should be thought about, at least somewhat, and that there's some common pitfalls to look out for.</p>
  
  <p>I can see though that it might be useful to also know why a tip is useful and where it should be applied. For the <code>StringBuilder</code> tip I found the help I did long ago at <a href="http://www.yoda.arachsys.com/csharp/stringbuilder.html" rel="noreferrer">here on Jon Skeet's site</a>. </p>