Best Practices‎ > ‎

C# - Guidelines

Collection of guidelines to follow related to the C# programming language.

  • Expose Collection<T> rather than List<T>
    According to the MS Code Analysis Team it is better to expose a Collection<T> rather than a List<T> directly (especially inside Frameworks). The main reason is that List<T> is optimized for performance and therefore for internal use (inside classes) while Collection<T> is designed for reusability. Read more here.

  • Use throw instead of throw ex
    Inside try-catch blocks, you should use throw; to further propagate exceptions instead of writing throw ex; because this resets the stacktrace.