The original of this document was developed by the Microsoft Special Interest Group. We made some Addons.
This document explains the naming conventions that shoshould be used with. Net projects.
A consistent naming pattern is one of the most important elements of predictability and discoverability in a managed class library. widespread use and understanding of these naming guidelines shoshould eliminate unclear code and make it easier for developers to understand shared code.
Capitalization styles defined
We define three types of capitalization styles:
Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
Example:
Backcolor, Dataset
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
Example:
Numberofdays, isvalid
Uppercase
All letters in the identifier are capitalized.
Example:
ID, Pi
Hungarian type notation defined
Hungarian notation is any of a variety of standards for organizing a computer program by selecting a schema for naming your variables so that their type is readily available to someone familiar with the notation. it is in fact a commenting technique.
Example:
Strfirstname, inumberofdays
There are different opinions about using this kind of type notation in programming nowadays. some say that it's useful, and it shoshould be used everywhere to enhance clarity of your code. others say it just obfuscates your code, because it has no real advantage in modern programming environments.
Our point of view is a moderated one: Use it wisely, meaning, we only use Hungarian notationPrivate or local variables, That are only accessible and interesting to the programmer of the class.
Don't use it with publicVariables, properties or parameters in methods, because they are exposed to the outside world. someone who uses your classes and accesses properties of your class, is not interested in type, but just wants to use them.
In the. NET Framework, there are a lot of types, So we extended and adapted the Hungarian notation with our own type notation.
Naming guidelines1). Private variables (fields in C #) naming guidelines Naming guidelines
Prefix private variables with a "_" and Hungarian-style notation.
Case guidelines
Use camel case as a general rule, or uppercase for very small words
Example:
_ Strfirstname, _ dsetemployees
// Field Private oledbconnection_ Connection;
// Property Public oledbconnection connection { Get {return_Connection ;} Set {_ COnnection = value ;} }
2). Local variables naming guidelines Naming guidelines
Prefix private or local variables with Hungarian-style notation.
Case guidelines
Use camel case as a general rule, or uppercase for very small words
Example:
Strfirstname, dsetemployees
3). namespace naming guidelines Naming guidelines
The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design as follows:
CompanyName. policyname [. Feature] [. Design]
Prefixing namespace names with a company name or other well-established brand avoids the possibility of two published namespaces having the same name. use a stable, recognized technology name at the second level of a hierarchical name.
Example:
Akadia. Traffic, system. Web. UI, system. Windows. Forms
Case guidelines
Use Pascal case as a general rule, or uppercase for very small words.
Example:
System. Windows. Forms, system. Web. UI
4). Class naming guidelines Naming guidelines
Use a noun or phrase to name a class. Do not use a type prefix, such as C for class, on a class name. Do not use the underscore character (_).
Case guidelines
Use Pascal case. Example:
Filestream, button
5). Interface naming guidelines Naming guidelines
Prefix interface names with the letter "I", to indicate that the type is an interface. Do not use the underscore character (_).
Case guidelines
Use Pascal case. Example:
Iserviceprovider, iformatable
6). Parameter naming guidelines Naming guidelines
Use descriptive parameter names. parameter names shocould be descriptive enough that the name of the parameter and its type can be used to determine its meaning in most scenarios. To distinguish parameters from other variables the prefix"P"Shocould be used.
Do not prefix parameter names with Hungarian type notation.
Do not use a prefix for parameter names of an event handler and exceptions.
Case guidelines
Use camel case. Example:
Ptypename, pnumberofitems
7). Method naming guidelines Naming guidelines
Use verbs or verb phrases to name methods.
Case guidelines
Use Pascal case. Example:
Removeall (), getcharat ()
8). Property/enumerations naming guidelines Naming guidelines
Use a noun or phrase to name properties. Do not use Hungarian notation.
Case guidelines
Use Pascal case. Example:
Backcolor, numberofitems
9). Event naming guidelines Naming guidelines
Use an eventhandler suffix on event handler names.
Specify two parameters named sender and E. the sender parameter represents the object that raised the event. the sender parameter is always of type object, even if it is possible to use a more specific type. the State associated with the event is encapsulated in an instance of an event class named"E". Use an appropriate and specific event class for the E parameter type.
Name an event argument class withEventargsSuffix.
Case guidelines
Use Pascal case. Example:
Public Delegate void mouseeventhandler (Object sender, mouseeventargs E );
9). Exception naming guidelines Naming guidelines
Event Handlers in Visual Studio. NET tend to use an "E" parameter for the event parameter to the call. To ensure we avoid a conflict, we will use"Ex"As a standard variable name for an exception object.
Example
Catch (exceptionEx) { // Handle exception }
10). Constant naming guidelines
The names of variables declared class constants shocould be all uppercase with words separated by underscores. It is recommended to use a grouping naming schema.
Example (for group ap_win ):
Ap_win_min_width, ap_win_max_width, ap_win_min_hight, ap_win_max_hight
11). C # primitive type notation
Sbyte SY Short s Int I Long L Byte y Ushort us Uint UI Ulong ul Float F Double D Decimal Dec Bool B Char C
12). Visual control type notation
Assembly ASM Boolean bln Button BTN Char ch Checkbox cbx ComboBox CMB Container CTR Datacolumn dcol DataGrid dgrid Datagriddatetimepickercolumn dgdtpc Datagridtablestyle DGTS Datagridtextboxcolumn dgtbc Datareader dreader Datarow Drow Dataset dset Datatable dtable Datetime date Dialog Dialogresult Dr Double DBL Exception ex Groupbox gbx Hashtable htbl Imagelist IML Integer int Label LBL ListBox lbx Listview LV Marshallbyrefobject RMT Mainmenu mm Menuitem Mi MDI-frame Frame MDI-sheet Sheet Numericupdown NUD Panel pnl Picturebox PBX Radiobutton rbtn SDI-Form Sqlcommand sqlcom Sqlcommandbuilder sqlcomb Sqlconnection sqlcon Sqldataadapter sqlda Statusbar STB String Str Stringbuilder strb Tabcontrol tabctrl Tabpage Textbox tbx Toolbar TBR Toolbarbutton TBB Timer TMR Usercontrol USR Windowsprincipal WPL
|