Best Practices

This is a quick attempt to try and provide some guidelines, suggestions, recommendations, etc


1) No Namespaces
Do not use "using", prefix everything in full.
Always fully qualify the names from any namespace


2) Fewer files means more consistency


3) Always include curly brackets
Do not use the ternary operation ?
Use brackets for single line If statements


4) Declare the variables outside the Try block and initialise them inside the Try-block


5) Add local variables inside the try-block, not above


6) Always use this prefix inside classes


7) Use Pascal casing for class names and properties


8) Class Names should be nouns, noun phrases or adjective phrases and should not contain an underscore


9) Do not provide a default constructor for a structure ??


10) Member Names should be verbs or verb phrases


11) Use ex as the variable for a general exception


12) Windows Forms Controls
Do not change any of the properties in the designer.
Always change the properties in the code for more visibility.


13) Add suffixes
Add the suffix "_Delegate" to any delegates
Add the suffix "_EventArgs" to any classes that extend System.EventArgs
Add the suffix "Exception" to any types that inherit from System.Exception
Add the suffix "Stream" to any types that inherit from System.IO.Stream
Add the suffix "en" to any enumeration types


14) when naming private or internal fields, and prefix them with _


15) Write only one statement per line.


16) Write only one declaration per line.


17) If continuation lines are not indented automatically, indent them one tab stop (four spaces).


18) Add at least one blank line between method definitions and property definitions.


19) Use parentheses to make clauses in an expression apparent, as shown in the following code.


20) Do not add too many comments
Place the comment on a separate line, not at the end of a line of code.
Begin comment text with an uppercase letter.
End comment text with a period.
Insert one space between the comment delimiter (//) and the comment text, as shown in the following example.
Don't create formatted blocks of asterisks around comments.
Ensure all public members have the necessary XML comments providing appropriate descriptions about their behavior.


link - docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions




© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext