C # common naming rules Rollup

Source: Internet
Author: User
Tags uppercase letter

This article is reproduced from the script home

This article provides a detailed summary of the common naming conventions for C #. Share to everyone for your reference. Specific as follows:

Pascal rules
Capitalize the letters at the beginning of each word (such as testcounter).

Camel rules
Capitalize the beginning of a word other than the first word. such as. Testcounter.

Upper rules
Abbreviations for constants that are only one or two characters long are named, and a Pascal rule should be applied for more than three character lengths.

For example:

The code is as follows: public class Math
{
Public Const PI = ...
Public Const E = ...
Public Const Feigenbaumnumber = ...
}

The specific rules are summarized as follows:

class naming Guide

-The class name should be a noun and a noun phrase, using the complete word as far as possible.
-Using Pascal Rules
-Do not use the class prefix-do not use the underscore character (_).
-Sometimes you need to provide a class name starting with the letter I, although the class is not an interface. This is appropriate as long as I is the first letter of the entire word as part of the class name. For example, the class name Identitystore is appropriate.
-In the appropriate place, use compound words to name the derived class. The second part of a derived class name should be the name of the base class. For example, ApplicationException is the appropriate name for a class that derives from a class named Exception, because ApplicationException is a Exception. Please make reasonable judgments when applying this rule. For example, a Button is the appropriate name for a class that derives from Control. Although a button is a control, adding control as part of the class name causes the name to be unnecessarily long.

Interface Naming conventions

-the interface name should be a noun or noun phrase or an adjective describing its behavior, using the complete word as far as possible. (Example IComponent or ienumberable)
-Using Pascal Rules
-Prefix with the character I, followed by an uppercase letter (that is, the first letter of the interface name is capitalized)
For example:

The code is as follows: interface Icompare
{
int Compare ();
}

Enumerate naming rules

-Use Pascal casing for Enum type and value name.
-Use fewer abbreviations.
-Do not use the enum suffix on the enum type name.
-use singular names for most enum types, but use plural names for enum types that are bit fields.
-Always add FlagsAttribute to the domain Enum type in place.


Variable naming

-Counter variables in simple loop statements using I, J, K, L, M, n
-Use Camel naming conventions

Method naming

-Using Pascal Rules
-Use a consistent verb/object or object/verb sequence for the method name. For example, when you put a verb in front, you use names such as Insertwidget and Insertsprocket, and when you put the object in front, you use names such as Widgetinsert and Sprocketinsert.
-The recommended name should be a verb or a verb phrase. For example Save,savecustomer, instead of using Customersave
-Do not repeat the name of the class in the method. For example, if a class is named book, do Not call a method Book.closebook, but you can name the method Book.close.

Attribute naming

-Name should be noun and noun phrase
-Using Pascal Rules
-for bool type attributes or variables using is as a prefix, do not use the flag suffix, for example, you should use isdeleted instead of using Deleteflag

Collection naming

-Name should be noun and noun phrase
-Using Pascal Rules
-Append "Collection" after name

Event naming

-the event handlers is named using the EventHandler suffix.
-Two parameters using sender and E, respectively
-Using Pascal Rules
-Event parameters using EventArgs suffix
-Event naming uses syntactic tenses to reflect the state of its excitation, such as changed,changing.
-Consider using a verb to name it. Variable naming
-Counter variables in simple loop statements using I, J, K, L, M, n
-Use Camel naming conventions

Custom properties End With attribute

The code is as follows: public class Authorattribute:attribute
{
}

The custom exception ends with exception
The code is as follows: public class Appexception:exception
{
}

other common coding rules

The indentation of the code. Use tab instead of space.
The name of the local variable should be meaningful. Do not use X, Y, Z, etc. (you can use I,j,k,l,m,n in addition to the for loop variable).
All member variables are declared at the top of the class and separated by a newline.
Name namespace with meaningful names, such as: Product name, company name.
Always use "{}" to include statements under if, even if there is only one statement.
Put similar content together, such as data members, attributes, methods, events, etc., and use #region ... #endregion.

The summary of the naming convention is expressed in a table as follows:

Related to class:

Identifier

Uppercase and lowercase

Example

CLASS/Structure

Pascal

AppDomain

Enum type

Pascal

ErrorLevel

Enumeration values

Pascal

FatalError

Event

Pascal

ValueChange

Exception class

Pascal

WebException

Note always end with a Exception suffix.

Read-only static fields

Pascal

Redvalue

Interface

Pascal

IDisposable

Note always start with the I prefix.

Collection

Pascal

Customercollection attention always ends with collection.

Method

Pascal

Tostring

Name space

Pascal

System.Drawing

Parameters

Camel

TypeName

Property

Pascal

BackColor

Protected instance Fields

Camel

Redvalue

Attention is seldom used. Properties are better than using protected instance fields.

Public instance Fields

Pascal

Redvalue

Attention is seldom used. Properties are better than using public instance fields.

Variable and method parameter naming: Variable description According to different data type prefix + First letter capitalization

Related to variable naming

Type

Prefix

Example

Array

Arr

Arrshoppinglist

Boolean

bln

Blnispostback

Byte

Byt

Bytpixelvalue

Char

Chr

Chrdelimiter

Datetime

Dtm

Dtmstartdate

Decimal

Dec

Decaverageheight

Double

Dbl

Dblsizeofuniverse

Integer

Int

Introwcounter

Long

Lng

Lngbillgatesincome

Object

Obj

Objreturnvalue

Short

Shr

Shraverage

Single

Sng

Sngmaximum

String

Str

strFirstName



Related to ADO

Data type

Data type Shorthand

Example of standard naming

Connection

Con

Connorthwind

Command

Cmd

Cmdreturnproducts

Parameter

Parm

Parmproductid

DataAdapter

Dad

Dadproducts

DataReader

Dtr

Dtrproducts

DataSet

Dst

Dstnorthwind

DataTable

Dtbl

Dtblproduct

DataRow

Drow

DrowRow98

DataColumn

Dcol

Dcolproductid

DataRelation

Drel

Drelmasterdetail

DataView

Dvw

Dvwfilteredproducts



Related to page controls

Data type

Data type Shorthand

Example of standard naming

Label

LbL

Lblmessage

LinkLabel

Llbl

Llbltoday

Button

Btn

Btnsave

Textbox

Txt

Txtname

MainMenu

Mmnu

Mmnufile

CheckBox

Chk

Chkstock

RadioButton

Rbtn

rbtnselected

GroupBox

Gbx

Gbxmain

PictureBox

Pic

Picimage

Panel

PnL

Pnlbody

Datagrid

Dgrd

Dgrdview

ListBox

Lst

Lstproducts

CheckedListBox

Clst

Clstchecked

ComboBox

Cbo

Cbomenu

Listview

Lvw

Lvwbrowser

Treeview

Tvw

Tvwtype

TabControl

Tctl

tctlselected

DateTimePicker

Dtp

Dtpstartdate

HscrollBar

Hsb

Hsbimage

VScrollBar

Vsb

Vsbimage

Timer

Tmr

Tmrcount

ImageList

Ilst

Ilstimage

ToolBar

Tlb

Tlbmanage

StatusBar

StB

Stbfootprint

OpenFileDialog

Odlg

Odlgfile

SaveFileDialog

Sdlg

Sdlgsave

Foldbrowserdialog

Fbdlg

Fgdlgbrowser

FontDialog

Fdlg

Fdlgfoot

ColorDialog

Cdlg

Cdlgcolor

PrintDialog

Pdlg

Pdlgprint



Related to page controls

Data type

Data type Shorthand

Example of standard naming

AdRotator

Adrt

Example

Button

Btn

Btnsubmit

Calendar

Cal

Calmettingdates

CheckBox

Chk

Chkblue

CheckBoxList

Chkl

Chklfavcolors

CompareValidator

Valc

Valcvalidage

CustomValidator

Valx

Valxdbcheck

Datagrid

Dgrd

Dgrdtitles

DataList

Dlst

Dlsttitles

DropDownList

Drop

Dropcountries

HyperLink

Lnk

Lnkdetails

Image

Img

Imgauntbetty

ImageButton

Ibtn

Ibtnsubmit

Label

LbL

Lblresults

LinkButton

Lbtn

Lbtnsubmit

ListBox

Lst

Lstcountries

Panel

PnL

PnlForm2

PlaceHolder

Plh

Plhformcontents

RadioButton

Rad

Radfemale

RadioButtonList

Radl

Radlgender

RangeValidator

Valg

Valgage

Regularexpression_r

Vale

Valeemail_validator

Repeater

Rpt

Rptqueryresults

RequiredFieldValidator

Valr

Valrfirstname

Table

Tbl

Tblcountrycodes

TableCell

Tblc

Tblcgermany

TableRow

Tblr

Tblrcountry

Textbox

Txt

txtFirstName

ValidationSummary

Vals

Valsformerrors

Xml

Xmlc

Xmlctransformresults

C # common naming rules Rollup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.