Tips for optimizing C#/.NET programs

Posted by Bob on Stack Overflow See other posts from Stack Overflow or by Bob
Published on 2010-03-18T22:07:15Z Indexed on 2010/03/18 22:11 UTC
Read the original article Hit count: 324

Filed under:
|
|

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 5 miles in the snow?

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:

  • When concatenating many strings together use StringBuilder instead. If you're only concatenating a handful of strings it's ok to use the + operator.
  • Use string.Compare to compare 2 strings instead of doing something like string1.ToLower() == string2.ToLower()

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET