Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Easy Naming Practices for .NET Coding

0.00/5 (No votes)
18 Mar 2006 1  
While writing codes for .NET applications, if you and your team members contain some common naming practices, it becomes very useful, especially when you're reading your existing codes and modifying your codes in Visual Studio .NET IDE.

Introduction

While writing codes for .NET applications, if you and your team members have some common naming practices, it becomes very useful especially when you're reading your existing codes and modifying your codes in Visual Studio .NET IDE. For naming conventions, I went to the MSDN site, but got so many links which made me a bit frustrated to read all the stuffs by spending couple of hours. However I have used my Microsoft Word application and very quickly written some naming conventions, which can be read and can be used very quickly. My team has found it fruitful; I believe you can find it useful as well.

UI Naming Prefix

1 Buttons btn
2 DropDownList ddl
3 LinkButton lnb
4 Label lbl
5 Repeater rpr
6 DataGrid dgd
7 CheckBox chk
8 RadioButton rdo
9 DataList dls
10 Image img
11 TextBox txt
12 ImageButton imb
13 HyperLink hln
14 ListBox lst
15 Panel pnl
16 PlaceHolder phd
17 Calendar cnd
18 AdRotator art
19 Table tbl
20 RequiredFieldValidator rfv
21 CompareValidator cmv
22 RangeValidator rgv
23 RegularExpressionValidator rev
24 CustomValidator csv
25 Validation Summary vsm

Casing of Codes

Name Space Name Case NameSpaceName
Class Naming Case ClassName
Method Naming Case MethodName
Property Naming Case PropertyName
Enum Case EnumName
Enum Members EnumMemberName
Constant Name Case ConstantName
Local Variable Naming Case variableName
Param Variable Naming Case paramName
Region Names Region name will be sentence case like this.
Code Comments Comments will be in general case like this.
Private Data _privateDataName

Database

Tables, Relations

Table Name Prefix tbl
Table Name Case tblTableName
Primary Key Name PK_tblNameID
Foreign Key Name FK_'ForeignKeytblName'ID

Stored Procedure

Stored Procedure Prefix

  • spr_StoredProcedureName

NOTE: Starting by sp_ prefix causes performance overhead.

CRUD (Create-Read-Update-Delete) Stored Procedures Names

INSERT spr_tblTableName_Insert
UPDATE spr_tblTableName_Update
DELETE spr_tblTableName_Delete
READ BY PRIMARY KEY spr_tblTableName_GetByPrimaryKey
READ BY FOREIGN KEY spr_tblTableName_GetBy'KeyName'
READ ALL spr_tblTableName_GetAll

NOTE 1: This standard groups the stored procedures by table wise cluster, which facilitates changes on a table schema modification in the stored procedure layer.

NOTE 2: For multiple table CRUD operation, use the following example:
INSERT: spr_tblTableName[1_tblTableName2_...tblTableNameN ]_Insert

Other Database Objects

Function Name Prefix fnc_
Trigger Name Prefix trg_
Cursor Name Prefix crs_
View Name Prefix viw_

CRUD [Create-Read-Update-Delete] Methods of Data Access Class

Methods

  • CreateEntityName
  • UpdateEntityName
  • DeleteEntity
  • GetAllEntityName
  • GetEntityNameById
  • GetEntityNameBy'KeyName'

NOTE: For DAL/BLL when there is a separate class for each entity, we can exclude the entity name from the method names.

Property

  • FieldName

Property Constants

  • _FieldName

Method Parameter that is Assigned to Property

  • fieldName

Conclusion

Any advice or correction for this article will be highly appreciated.

History

  • 18th March, 2006: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here