Skip to content

ProgrammingTips

Eduard Scherf edited this page Feb 15, 2022 · 3 revisions
  • Avoid plain strings as output property type to pass structured data which needs to be parsed. Instead consider using an array, a set, a dictionary or similar.
  • Use the .NET Attribute [Conditional("DEBUG")] for debug methods which should not be called in the Release version. Inside a conditional method you can print a stacktrace, check debugging assertions or similar.
  • Do not use Encoding.Default, as it may be ambigious. Use Encoding.UTF8.

Performance

  • Avoid using IndexOf(...) in loops. It's a quite costly operation.
  • Avoid using exceptions for normal program flow. Exceptions shall be used for (exceptional) error conditions. Do not use exceptions for your regular program control (as additional return point or similar).
  • VS2008Profiling Profile your application with VS 2008 Team System (similar to VS2010 Ultimate).
  • Set unneeded static or member variables to null. In most situations the GC knows by itself how to clean up data. However when you keep references in static or member variables, it can't see that the data is unused.
  • Avoid editing strings in loops. String objects are immutable which means that each change requires the instantiation of a new object. Use StringBuilder instead.

Other Resources

  • You can use FXCop to analyze your assemblies for convention violations and improvement hints. Sometimes FXCop may point to a defect but in most cases it will show style and beautification issues.
  • Microsoft has some useful Design Guidelines.
Clone this wiki locally