Table of Content
- Theoretical Concepts
- Fundamental Concepts
- Object Oriented Concepts
- Advanced Concepts
Common Commands
Create a .NET class library using Visual Studio Code - .NET | Microsoft Docs
Best Practices and Coding Convention
- For Local variables, Method parameters use Camel Case
- For Constants, Method names, Class Names, Public Class Fields and Properties use Pascal Case
- Class Fields that are private should be written in Camel Case with a leading underscore (e.g.
_firstName
) - Interface names should start with capital “I” and be in Pascal Case (ITaxCalculator)
- When creating Generic types the name should start with “T” followed by name in Pascal Case (TKey, TValue)
- Only one class should below to an file and the filename should be came as the class name
- Avoid using Ref and Out Method Modifiers as they are seen as code smell and makes the flow difficult to understand
- Auto-implemented properties should be placed at the top of the class followed by the Constructor and then Properties
- Avoid using Protected and Protected Internal Access Modifiers whenever possible
- Should avoid Boxing and Unboxing of fields whenever possible
Miscellaneous Points
New Keyword
The new keyword is used to allocate memory for an instance of an object
C# Objects
All objects in C# have a ToString()
method which makes it easy to convert any datatype to string (This method is inherited from the Object Class which is the base class for all objects)
Object Initialization
During object initialization all reference type objects are set to null. If need to pass a reference type object to a class always initialize it using a Constructor to avoid Null Exception
Var Datatype
The var datatype cannot be used to declare fields in the class scope (Class Fields). If used the variable has to be initialized and declared on the same line
Named and Optimal Arguments
Named arguments can be used when we don’t know the order of arguments to be passed to the method
Predicate Functions
Functions that return a Boolean result is called as predicate function