1. Knowing when to use StringBuilder
2. Comparing Non-Case-Sensitive Strings
str1.ToLower() == str2.ToLower()
string.Compare(str1, str2, true) == 0 //Ignoring cases
3. Use string.Empty
if (str == "")
if (str == string.Empty)
4. Replace ArrayList with List<>
ArrayList intList = new ArrayList(); intList.add(10); return (int)intList + 20;
List<int> intList = new List<int>(); intList.add(10) return intList + 20;
5. Use && and || operators
if (object1 != null && object1.runMethod())
6. Smart Try-Catch
7. Replace Divisions
ConclusionAs you can see these are very simple C# code optimizations and yet they can have a powerful impact on the performance of your application. To test out the optimizations, try out the free Optimizing Utility.
ProfilingAn important concept when it comes to increasing the speed and efficiency of you C# code, is code profiling. A good profiler can not only let you know about the speed bottlenecks in your applications, but it can also help you with memory management. The best .Net profiler is probably RedGates ANTS Profiler. They have a free trial at their homepage you can download before purchasing the full product.