C # Named rules and development habits (BLOG) of Star Bright Crystals (ZJ492) in Heaven

xiaoxiao2021-03-06  108

First, name

1. Use the PASCAL rules to name the method and type, and the class name adds a CLS prefix.

The PASCAL rule is: The first letter must be capitalized, and the first letter of the back and seminated consensus is uppercase, such as GeneralManager, SmallDictionary, Stringutil is a class name of this rule.

Public Class ClstextBox

{

Public void databind ()

{

}

}

2. Use the Camel rules to name the local variables and methods. And add the data type prefix. (Prefix but refer to appendix)

The Camel rule is: the first letter of all substrings outside the first substrong

String strusername;

Public adduser (String struserid, byte [] bypassword);

3. All member variables prefix M_

Public Class Database

{

Public string m_strconnectionstring;

}

4. The name of the interface adds prefix I.

Interface iCompare

{

INTCOMPARE ();

}

5. Customized properties end with Attribute

Public Class AuthorAttribute: Attribute

{

}

6. Customized exception ends with the EXCEPTION

Public Class APPEXCEPTION: Exception

{

}

7. Naming method. Generally named by a mobile phrase.

Showdialog ()

Createfile ()

GetPath ()

8. Corridation. To use Tab, not to use Space.

9. The name of the local variable must be meaningful. Do not use x, y, z, etc.

String Username

10. All member variables are declared at the top of the class and separate it from a wrap.

11. Name Namespace with meaningful name, such as: product name, company name.

12. It is recommended that local variables declare when it is closest to it.

13. When using a control value, try to name local variables.

14. Separate the Namespace from the referenced system and custom or third parties.

15. The file name is to react the content, it is best to be a class with the same name, a class in a file.

16. Big bracket "{" To a new line.

Public Class AuthorAttribute: Attribute

{

}

17 constant

All uppercase, the words are separated by "_"

User_password

Second, the coding habit.

1. Use the C # predefined class name instead of alias.

String username; not system.string username;

Int number; not system.int32;

2. Do not exceed 80 characters in one line.

3. Try not to manually change the code generated by the machine. If you must change, be sure to change it to the code style generated by the machine.

4. Key statements (including a key variable) must write comments.

5. Text constants and digital constants do not have hard coding, and should be replaced with constant classes or enumerations.

6. Don't use the GOTO family of statements.

7. Do not declare the member variables of public and protected, apply Property.

8. Do not declare the EVENT of the public, Apply Event Accessor.

Public Class Source

{

PRIVATE EVENTHANDLER M_NUMBERCHANGEVENT;

Public Event athandler NumberchangeEvent

{

Add

{

m_numberchangeeevent = value;

}

Remove

{

m_numberchangeeevent - = value;

}

}

}

9. Use rules for type conversion.

Animal Animal = New Dog ();

DOG DOG = Animal As Dog;

IF (Dog! = NULL)

{

}

10. When generating and build a long string, you must use StringBuilder without String.

11. Always use "{}" containing statements under IF / ELSE, even if there is only one statement.

12.switch statement must have DEFAULT to handle unexpected.

13. Try not to use this reference unless there is another constructor to call the class.

Public Class Person

{

Public Person (String Name)

{

}

Public Person (): this ("jim")

{

}

}

Database Naming Rule 1, Database Object Name Rules: TB_E | R | B_ The relatively independent entity table in the first letter in the E-business table (for example: course resource table ...) R-business is generated in the R-business ( For example: class table ...) B - system Basic table (eg type table, nation, region ...) Tu | TD_ First Letter Overrord Function Process: Fn_ The first letter capital 3, data item naming rule column name naming rules: first letter Note: Recommended name part with English words or words Shorthand: Data type

BOOL-B FLOAT-FLT UNIT-UI BYTE-BY IT-I ULONG-ULNG CHAR-CH Long-LNG Ushort-Usht Decimal-Dec Sbyte-Sby String-Str Double-DBL Short-Sht Object-Obj Emun-Emn Struct- ST

Control naming:

Control Type Prefix EXAMPLE

3D PANEL PNL PNLGroup

ADO Data Ado Adobe Iblio

Animated Button Ani Animailbox

Button BTN BTNOK

Check Box Chk ChkReadonly

Combo Box CBO CBOENGLISH

DropDown List Box DDL DDLUSER

Command button cmd cmdexit

Common Dialog Dlg DlgfileOpen

Communications Com ComfaxControl (Used with Xin Procedures When Thepe IS unknown)

Ctr Ctrcurrent

Data Dat Datbiblio

Data-Bound Combo Box DBCBO DBCBOLANGUAGE

Data-Bound Grid DBGRD DBGRDQUERYRESULT

Data-Bound List Box DBLST DBLSTJOBTYPE

Data Combo DBC DBCAUTHOR

Data Grid DGD DGDTISLES

Data List DBL DBLPUBLISHER

Data Repeater Drp Drplocation

Date Picker DTP DTPPBLISHED

Directory List Box Dir Dirsource

Drive List box drv drvtarget

File List Box FilSource

Flat Scroll Bar FSB FSBMOVE

Form FRM FRMENTRY

Frame fraranguage

Gauge Gau Gaustatus

Graph gra grandevenue

Grid GRD GRDPRICES

Hierarchical FlexGrid Flex Flexorders

Horizontal Scroll Bar HSB HSBVOLUME

Image IMG IMGICON

Image Combo Imgcbo IMGCBOPRODUCT

ImageList Ils Ilsallicons

Label LBL LBLHELPMESSAGE

LightWeight Check Box LWCHK LWCHKARCHIVE

Lightweight Combo Box LWCBO LWCBOGERMANLIGHTWEIGHT COMMAND button LWCMD LWCMDREMOVE

Lightweight Frame LWFRA LWFRASAVEOPTIONS

Lightweight Horizontal Scroll Bar LWHSB LWHSBVOLUME

Lightweight List Box LWLST LWLSTCOSTCENTERS

Lightweight Option Button Lwopt LwoptIncomeLevel

LightWeight Text Box LWTXT LWOPTSTREET

Lightweight Vertical Scroll Bar LWVSB LWVSBYEAR

Line Lin Linvertical

List box Lst LstpolicycoDes

Listview lvw lvwheadings

Mapi Message MPM MPMSentMessage

Mapi session MPS MPSSession

MCI MCI McIvideo

Menu Mnu Mnufileopen

Month View MVW Mvwperiod

MS Chart Ch ChsalesbyRegion

MS Flex Grid Msg MsgClients

MS Tab MST MSTFIRST

Ole Container Ole Oleworksheet

Option Button Opt Optgender

Picture Box Pic Picvga

Picture CLIP CLP CLPToolbar

ProgressBar PRG prgloadfile

Remote Data Rd Rdtitles

RichtextBox RTF RTFreport

Shape SHP SHPCIRCLE

Slider SLD SLDSCALESPIN SPN SPNPAGES

Statusbar Sta StadateTime

Sysinfo Sys Sysmonitor

Tabstrip Tab TabOptions

Text box txt txtlastname

Timer TMR Tmralarm

Toolbar TLB TLBACTIONS

TreeView Tre Treorganization

Updown UPD UPDDIRECTION

Vertical Scroll Bar vsb vsbrate

转载请注明原文地址:https://www.9cbs.com/read-125886.html

New Post(0)