Skip to main content

Posts

Showing posts with the label C# Coding Standards

C# coding best practices with examples

 C# coding best practices and coding standards are guidelines and conventions that developers should follow to write maintainable, readable, and efficient code. Here are a few examples of C# coding best practices:     1) Use meaningful and consistent naming conventions. For example, use camelCase for local variables and PascalCase for class and method names.     2) Use the using statement for disposable objects, such as file streams and database connections, to ensure that they are properly disposed of.     3) Use the async and await keywords to make asynchronous calls and avoid blocking the UI thread.     4) Use exception handling to handle errors and unexpected conditions. Use specific exception types rather than the base Exception type.     5) Use the null-coalescing operator (??) to provide a default value when a nullable type is null.     6) Use StringBuilder instead of concatenating strings in a loop.     7) Use the ?. operator to check for null values before accessing an object&

C# Coding Best Practices, Coding Standards : Quick Guide

C# Coding Best Practices, Coding Standards A Quick table to identify when to use what.   Starts With Writing Style Example Class Any Pascal Case MyClass Struct Any Pascal Case MyStruct Interface I Pascal Case IMyInterface Private Fields _(Underscore) Camel Case _userName Internal Fields _(Underscore) Camel Case _userName  For more detailed information see here