Coding Standard
Today, when you are developing an application, I will explain to you the Naming Convention of C # Coding Standards for best practice of C# coding.
Types:-
CamelCase (camelCase): In this (camelCase) the first letter of the word always in small letter and after that each word with capital letter.
Pascal Case (PascalCase): In this (PascalCase) the first letter of every word is in capital letter.
Underscore Prefix (_underscore): For underscore (_), the word after _ use camelCase term.
Congenital Datatype
Always use native datatype instead of .NET. Example, use int instead of Int16 or Int32.
Do not use the short form. Use the name, address, salary etc. instead of nam, addr, sal.
Do not use single character variable names like a, b, c, etc. Use names like index and temp.
Do not use underscores (_) in variable names.
Namespace names should follow the standard pattern.
According to my own definition, the following are the characteristics of the code.
- Reliable
- Maintainable
- Efficient
Here the naming conferences, coding standards and the best practices described in this document have been compiled by our own experience and by mentioning various Microsoft and non-Microsoft guidelines.
Purpose of coding standards and best practices
To develop a reliable and maintainable application, you must be follow coding standards and best practices.
The naming conventions or coding standards and best practices described in this document are compiled from my own experience and by referring to various Microsoft and non-Microsoft guidelines.
There are various standards exists in the programming area. None of them is wrong or bad and you can follow the code of any of them.
And most importantly, you choose a standard approach and also ensure that everyone is following it.
Always use PascalCase for a namespace.
namespace StanderedProgramming.Domain
Methods
Always use PascalCase for method names. The maximum 7 parameters for the method should be used.
Note: Don't use a name as all character in CAPS.
Always use PascalCase for class names. Try to use a noun or noun phrase for a class name.
Arguments and Local Variable
We should always use camelCase for method arguments and local variables. we should not use Hungarian notation for any variables.
Note: Don't use the short form for any words and don't use an underscore (_) in between any name.
Property
Use PascalCase for the property. Never use Get and Set as a prefix with the property name.
Interface
Always use the letter "I" as a prefix with the name of an interface. After letter I, use PascalCase.
Private Member Variable
Always try to use camelCase terminology prefix with an underscore ( _ )
Member variable
Declare member variable at the top of the class, if the class has static member then it will come at the topmost and after that other member variable.
Enum
Always use a singular noun to define Enum.
btn | Button |
cb | CheckBox |
cbl | CheckBoxList |
ddl | DropDownList |
fu | FileUpload |
hdn | HiddenField |
txt | TextBox |
hlk | Hyperlink |
img | Image |
lbl | Label |
lbtn | LinkButton |
mv | MultiView |
pnl | Panel |
dtg | DataGrid |
imb | ImageButton |
lst | ListBox |
dtl | DataList |
rep | Repeater |
rdo | RadioButton |
rdl | RadioButtonList |
phd | Placeholder |
tbl | Table |
gv | GridView |
dtv | DetailView |
fv | FormView |
Today we learned coding standard naming conventions in C#. Thanks for reading this article, hope you enjoyed it.
Leave Comment