Naming Conventions and Coding Standards in ASP.NET (C#)


Hello Friends,
As Programmer your role is not just to write the code and run the application, for a good programming skills and better understating codes you should follow some tips like Naming convention, comments, and variable declaration etc.
Here are few points I have gathered and collected for you, how we should do coding and use naming convention.  Here in our code we use Pascal Casing and Camel Casing.
Pascal Casing - First character of all words are Upper Case and other characters are lower case.
ex: EmpMaster
Camel Casing - First character of all words, except the first word are Upper Case and other characters are lower case.
ex: empMaster
Pascal casing: used for class Name and method Name
//This is my Class and single line comments example
public class HelloWorld
{
       ...
}

/*This is my Method and
multi line comments example
*/
void SayHello(string name)
{
       ...
}

Camel casing: used for variables and methods parameter
int inttotalCount = 0;
void SayHello(string strname)
{
       string strMessage = "Hello " + strname;
       ...
}

Variables:
Use Meaningful, descriptive words to name variables. Do not use abbreviations.

string strName                                  --good practice
int  intAge                                           --good practice
string strNam                                     --bad practice
int  intAg                                              --bad practice

Prefix for Controls Ids
Always use proper prefix for control here are the few examples:
Control                                                 Prefix                                    Example
Label                                                     lbl                                            lblName
TextBox                                                txt                                           txtName
DropDownList                                      ddl                                          ddlCity
CheckBox                                             chk                                         chkTerms
RadioButton                                         rbt                                           rbtMale
GridView                                              grv                                           grvCustomer

Comments