C # program coding specification

xiaoxiao2021-03-06  96

C # program coding specification

1. Purpose

In order to ensure that the procedures prepared by the company are in line with the same specifications, the program coding specifications established by the consistency and unity are guaranteed.

2. area

Applicable to software development work based on .NET platform.

3. Specification content

3.1. Code format

1. All indentation is 4 spaces, using the default settings for VS.NET.

2. Vertical to left parentheses and right brackets in the code.

IF (x == 0)

{

Response.write ("The user number must be entered!");

}

Not allowed to:

IF (x == 0) {

Response.write ("The user number must be entered!");

}

or:

IF (x == 0) {response.write ("The user number must be entered!");

3. In order to prevent the source code editor from reading the code, each line code or comment must not exceed a display at 1024 * 800 display frequency, and when the line is divided into several lines, the series operator is placed At the end of each row, it is not started, clearly indicates that there is no end behind it.

4. The statement placed on each line avoids more than one.

5. Use space before and after most operators, do not change the intent of the code, but you can make the code easy to read.

example:

INT j = i k;

Not writing

INT j = i k;

6. Divide a large complex code section into a smaller, easy to understand.

7. When writing SQL statements, use all uppercases for keywords, use case-write mixing for database elements (such as tables, columns, and views).

Place each primary SQL clause on a different line, which is easier to read and edit statements, for example: select firstname, lastname

From customer

Where stat = 'wa'

3.2. Note (Comment) Specification

Note specification includes: module (class) annotation specification, class properties, method comment specification, inter-code interpretation

3.2.1. Module (class) annotation specification

The module must be written in the following form:

///

/// Module number:

/// Effect:

/// Authors: Chinese name

/// Write the date:

///

If the module has a modification, you must add the following notes each time you modified:

///

/// log number:

/// Modify Description:

/// Author: modified by Chinese name

/// Modify Date:

///

3.2.2. Class attribute annotation specification

Attributes in the class must be written in the following format:

///

/// attribute description

///

3.2.3. Method Note Specification

Notes must be written in the following format before declaration of the class

///

/// Description:

///

/// ///

///

///

3.2.4. Code interpretation specification

Inter-code interpretation is divided into single line annotations and multi-line comments:

Untrue annotation:

//

Multi-line comments:

/ * Multi-line Note 1

Multi-line notes 2

Multi-line comment 3 * /

When you encounter a statement block, you must add a comment (if, for, foreach, ...), the added annotation must be able to illustrate the function and implementation means of this statement (algorithm, etc.).

3.3. Variable (variable) naming specification

3.3.1. Variable naming rules in program file (* .cs)

The Variable Name = Varfix of the Variable English Words or Word Abbreviations of Variables.

1. Use "m_" to prefix with "M_" variables

Public Class Hello

{

Private string m_name;

PRIVATE date M_Date;

}

2. Variables corresponding to the attributes of the class, using the "M_" prefix in the attribute name

Public Class Hello

{

Private string m_name;

Public String Name

{

get

{

Return M_Name;

}

}

}

3. The process-grade variable does not use a prefix

Public Class Hello

{

Void Say ()

{

String syeword;

}

}

4. Parameters of the process use "p_" as parameters

Public Class Hello

{

Void Say (String P_Sayword)

{

}

}

Supplementary description:

Named an Exception variable in the abnormal capture process, in the case where there is no conflict, uniformly name E;

If there is a conflict, you can repeat E, such as: EE.

Try

{

// Your Code

Try

{

// Code

}

Catch (Exception EE)

{

// Your Code

}

}

Catch (Exception E)

{

// Your Code

}

Supplement: If you do not need to make any processing, you don't need to define an Exception instance.

example:

Try

{

// Your Code

}

Catch (Exception)

{

}

5. In view of the fact that most names are constructed by connecting a number of words, use case-write mixed formats to simplify their reading. The first letter of each word is capitalized.

6. The meaningful name is still used even for variables that may only appear in several code lines. Use a single-letter variable name only for short cyclic indexes, such as I or J.

7. Use complementaries such as MIN / MAX, Begin / End and Open / Close in the variable name.

8. Do not use primary numbers or primary strings, such as for i = 1 to 7. But use naming constants, such as for i = 1 to num_days_in_week for maintenance and understanding.

3.3.2. Control Naming Rules

Control naming = web control abbrefix "_" variable name

Control

abbreviation

Label LBL

Textbox txt

Checkbox chk

Button cmd

Listbox LST

DropDownList DrP

and many more

3.4. Constant Name Specification

Constant numbers should also have some meaning, format is NOUN or Noun_Verb. The constant name is uppercase, and the word is separated by underline. example:

Private const bool web_enablepagecache_default = true;

Private const INT Web_pagecacheexpiresinseconds_default = 3600;

Private const bool_eb_enablessl_default = false;

Note:

The variable name and constant name can contain 255 characters, but the name of more than 25 to 30 characters is relatively awkward. In addition, you should take a name that has the actual meaning, clearly express variables or constants, 25 or 30 characters should be sufficient.

3.5. Class (CLASS) naming specification

1. The name should be able to identify the characteristics of things.

2. The name should not use abbreviations as much as possible unless it is well known.

3. The name can be composed of two or three words, but usually should not be more than three.

4. In the name, all words are the first letter.

For example, Issuperuser, containing ID, all uppercase, such as CustomerID.

5. Name the class or noun phrase.

6. Less use of abbreviations.

7. Do not use underscore characters (_).

example:

Public Class FileStream

Public Class Button

Public Class String, PUBLIC CLASS STRING

3.6. Interface Naming Specification

The same is the same as the class naming specification, the only difference is that the interface plus "i" prefix before the name.

example:

Interface idbcommand;

Interface ibutton;

3.7. Method Naming Specification

The same name naming specification.

3.8. Name Space (Namespace) Named Specification

The same name naming specification.

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

New Post(0)