h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Tips to improve performance of C# code

Tips to improve performance of C# code

  • Choose your data type before using it
  • Use For loop instead of foreach
  • Choose when to use a class and when to use a structure
  • Always use Stringbuilder for String concatenation operations
  • Choose best way to assign class data member
  • Boxing and UnBoxing
  • ‘as’ versus type casting
  • Control overflow checking
  •  Using readonly versus const
  • Avoid producing a lot of garbage
  • Avoid using finalizers when possible
  • Recycle and/ or cache objects
  • Reduce class hierarchy
  • Avoid explicitly calling the Garbage Collector
  • Avoid synchronization
  • Use Lazy Evaluation
  •  Optimized classes
  •  Explicitly close resources
  • Limit number of threads
  • Ternary Operator (?:)
  •  Null-Coalesce Operator (??)
  • Namespace Alias Qualifier
  • Object Initializers
  • Nullable Types
  • Type Inference
  • Lambda Expressions