Latest

random

Best Programming Practices - Naming Convention, Coding Standards

C# Coding Conventions (C# Programming Guide)

  • Use pascal casing for Class/Type names, constants and method names.
Use pascal casing for Class/Type names, constants and method names
  • Use camel casing for local variable names and method parameters.
Use camel casing for local variable names and method parameters.

  • Interface names should be prefix with "I" and follow pascal casing.
Naming conventions & standards
  • Do not use Hungarian notation to name variables: -   For example: string strEmployeeName, int nEmployeeAge, So to identify member variables follow camel casing as shown earlier.
  • Use Meaningful, descriptive words to name variables.
  •  Do not use abbreviations or contractions as parts of identifier names. For example, use OnButtonClick rather than OnBtnClick.
  • Name method names using verb-object pair, such as ShowEmployee().
  • Do not use single character variable names, such as i , j, k etc. instead of that use Index or Counter for example:
for (int counter = 0;  counter < count;  counter ++)
{
    ……..
}


  • Methods with return values should have a describing name the value it returns. E.g. GetEmployee().
  • Suffix custom exception classes with Exception.
Naming conventions & standards


  • Suffix custom attribute classes with Attribute.
  • Prefix boolean variables with “is”. E.g. isEmployeeDeleted.
  • While naming Namespace follow the standard : - <company name>.<product name>.<top level module>.<bottom level module> e.g. MyCompany.CMS.Web.Controls
  • Avoid fully qualified namespace for  Type. Good to use Using Statement.
  • Using Statements should be sort by framework namespaces and then  other namespaces.
Naming convention & standards
  • File name and class name should be same.
  • Use pascal casing for file name. Keep related Class files in single Class Library.
  • Declare local variable as close as possible for its first use.
  • All Member variables should be declared at the top, with one line separating them from Properties and Methods.
Naming conventions & standards

  • UI elements (Whether it is under Windows/Asp.Net) should use appropriate prefix so that you can identify them easily. Brief list given here:- 

Control
Prefix
Label
lbl
TextBox
txt
DataGrid
dtg
Button
btn
ImageButton
imb
Hyperlink
hlk
DropDownList
ddl
ListBox
lst
DataList
dtl
Repeater
rep
Checkbox
chk
CheckBoxList
cbl
RadioButton
rdo
RadioButtonList
rbl
Image
img
Panel
pnl
PlaceHolder
phd
Table
tbl
Validators
val


































Get in touch for more information. Happy Coding .. :-)

No comments:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.