Naming Conventions
C# Coding Standards and Naming Conventions
Do use PascalCasing for class names and method names:
Do use camelCasing for method arguments and local variables:
Do NOT use Hungarian notation or any other type identification in identifiers
Why: In general you want to avoid type indicators in any identifier.
Do NOT use Screaming Caps for constants or readonly variables
Why: Caps grap too much attention.
Avoid using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.
Why: Prevents inconsistent abbreviations.
Do use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase)
Why: Caps would grap visually too much attention
Do NOT use Underscores in identifiers. Exception: you can prefix private static variables with an underscore.
Why: makes code more natural to read (without 'slur'). Also avoids underline stress (inability to see underline).
Do use predefined type names instead of system type names like Int16, Single, UInt64, etc
Do use noun or noun phrases to name a class.
Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.
Do organize namespaces with a clearly defined structure
Do vertically align curly brackets.
Why: Microsoft has a different standard, but developers have overwhelmingly preferred vertically aligned brackets
Do declare all member variables at the top of a class, with static variables at the very top.
Why: generally accepted practice that prevents the need to hunt for variable declarations.
Do use singular names for enums. Exception: bit field enums
Why: consistent with the Microsoft's .NET Framework and makes the code more natural to read. Plural flags because enum can hold multiple values (using bitwise 'OR').
Do NOT explicitly specify a type of an enum or values of enums (except bit fields)
Why: can create confusion when relying on actual types and values.
Do NOT suffix enum names with Enum or Flags
Why: consistent with prior rule of no type indicators in identifiers
Do use suffix EventArgs / EventHandler / Exception to comprising the information:
Offical Reference
Naming Conventions for ASP.NET Controls
In general, naming ASP.NET controls is made using Camel Case naming convention, where the prefix of the name is the abbreviation of the control type name.
Standard Controls
Prefix | Control | Example |
btn | Button | btnSubmit |
cb | CheckBox | cbTerms |
cbl | CheckBoxList | cblTodos |
ddl | DropDownList | ddlCountries |
fu | FileUpload | fuVideo |
hf | HiddenField | hfBookId |
lnk | Hyperlink | lnkViewMore |
img | Image | imgBanner |
ibtn(btn) | ImageButton | ibtnDelete |
lbl | Label | lblName |
lbtn(btn) | LinkButton | lbtnSubmit |
lb | ListBox | lbSelectedItems |
lit | Literal | litOutput |
mv | MultiView | mvContainer |
pnl | Panel | pnlToggle |
ph | PlaceHolder | phMessage |
rb | RadioButton | rbStatus |
rbl | RadioButtonList | rblPackages |
tbl | Table | tblReport |
txt | TextBox | txtEmail |
v | View | vRegisterForm |
Data Controls
Prefix | Control | Example |
dtl(dl) | DataList | dtlMovie |
dp | DataPager | dpMovie |
dtv | DetailsView | dtvMovie |
ets | EntityDataSource | etsMovie |
fv | FormView | fvCheckout |
gv | GridView | gvMovie |
lds | LinqDataSource | ldsMovie |
lv | ListView | lvMovie |
ods | ObjectDataSource | odsMovie |
qe | QueryExtender | qeMovie |
rpt | Repeater | rptMovie |
smd | SiteMapDataSource | smdSitemap |
sds | SqlDataSource | sdsMovie |
xds | XmlDataSource | xmlPosts |
Validation Controls
Prefix | Control | Example |
cpv | CompareValidator | cpvConfirmPassword |
ctv | CustomValidator | cvPhoneNumber |
rv | RangeValidator | rvLimit |
rev | RegularExpressionValidator | revDomainUrl |
rfv | RequiredFieldValidator | rfvName |
vs | ValidationSummary | vsSummary |
Last updated