C# Coding Standards and Naming Conventions
DO
use PascalCasing for class names and method names.
use camelCasing for method arguments and local variables.
use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase).
use predefined type names instead of system type names like Int16, Single, UInt64, etc.
use implicit type var for local variable declarations. Exception: primitive types (int, string, double, etc) use predefined names.
use noun or noun phrases to name a class.
prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.
name source files according to their main classes. Exception: file names with partial classes reflect their source or purpose, e.g. designer, generated, etc.
organize namespaces with a clearly defined structure.
vertically align curly brackets.
declare all member variables at the top of a class, with static variables at the very top.
use singular names for enums. Exception: bit field enums.
DO NOT
use Hungarian notation or any other type identification in identifiers.
use Screaming Caps for constants or readonly variables.
use Underscores in identifiers. Exception: you can prefix private static variables with an underscore.
explicitly specify a type of an enum or values of enums (except bit fields).
suffix enum names with Enum.
AVOID
using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.
Use appropriate prefix for the UI
elements so that you can identify them from the rest of the
variables.
There are 2 different approaches recommended
here.
a. Use a common prefix ( ui_ )
for all UI elements. This will help you group all of the UI elements
together and easy to access all of them from the intelligence.
b.
Use appropriate prefix for each of the UI
element. A brief list is given below. Since .NET has given several
controls, you may have to arrive at a complete list of standard
prefixes for each of the controls (including third party controls)
you are using.
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 |
No comments:
Post a Comment