C # Coding specifications summarized by myself-1. Naming Conventions,
Recently, I have compiled c # coding standards for my company. I haven't studied much about this in the past. I just thought that the code can make my own sense.
I have referred to the following materials
It is very difficult to write a code specification. It depends on the experience of the coders, the level of team members, the specific business needs, and the complexity of the project, project Progress, corporate culture, and so on.
In addition, there are always a lot of ideas to write when writing a pen, but as a standard, it cannot be too long to be simplified.
Therefore, I wrote only the naming convention for two days. I would like to share with you some explanations on why this Convention should be selected, I hope you can discuss whether the rules I have selected are reasonable. If they are unreasonable, I am very happy to modify them with you.
In the next few days, I will
Ii. Naming
Iii. Compilation of Comments
At the same time, I hope you can help me think about what other aspects of coding specifications need to be covered.
Naming Conventions
When naming Identifiers (including parameters, constants, and variables), we should use the uppercase and lowercase letters of words to distinguish multiple words in an identifier, such as UserName.
PascalCasing contains one or more words. The first letter of each word is uppercase, And the other letters are lowercase. For example, HelloWorld and SetName.
In addition to parameters, variables, and constants, all namespaces, classes, functions, interfaces, attributes, events, and enumeration names are named in Pascal style.
CamelCasing contains one or more words. The first letter is lowercase, And the other letters are uppercase. For example, name and productId.
Use camelCasing to name parameters and variables.
SCREAMING_CAPS contains one or more words. All the letters of each word are uppercase. The words are connected by "_". Currently, this style is only used for const constants in c.
For example, public const string DEFAULT_PAGE = "default. aspx ";
Private variables use the underscore "_" + camelCasing case-sensitive rules to quickly confirm the scope of the variable.
For example, private int _ userId;
- Uppercase/lowercase letters
Acronyms are composed of the first letters of a phrase, such as Xml (ExtensibleMarkuLaguage) and I/O (Input and Output ). It is different from a word abbreviation. A word abbreviation only shortens the length of a word.
- Case sensitivity of Compound Words
Do not capital the first letter of a compound word. Compound Words should be treated as one word.
Such as endpoint, callback, metadata, and namespace.
- Add "_ camelCasing unit" to the variable with the unit value"
By adding the unit to the identifier name, you can quickly and accurately know the unit of the person data to reduce the occurrence of errors.
For example, public void CreateCache (int cacheSize)
Is the incoming data bytes, KB, MB, or GB?
Change to public void CreateCache (int cacheSize_mb)
It is clear and reduces the possibility of incoming error data by the caller.
Other function parameters without unit and versions with unit.
- Do not use the Hungarian naming convention
The Hungarian naming method uses the abbreviated data type in lower case as the prefix of the variable name. Such as strName and intCount.
This naming method is very popular in the C and C ++ times and can help programmers remember their own types.
However, it must be disabled in C # Unless you have enough reasons, because:
- Use English word order name identifier
When reading the code, you can better understand the naming rules that conform to your reading habits.
For example, verticalignment allows users to know the meaning of a variable faster than AlignmentVertical.
Summary of C language courses
At the end of the semester, I had some knowledge of the C language, but I felt that I had not learned very well. Fortunately, I still learned the knowledge:
I learned about C development and basic programming steps, Printf output statements, C language operations, and the types of data, as well as the frequently used if statements, if an eles statement, for loop, while statement, do-while statement, and so on, basically use arrays and pointers, as well as string processing, and the structure that can be learned.
There are still a lot of knowledge points, which are not listed one by one. In short, there are too many things to learn in C language. It is very easy to hear C from the sophomore and junior students, but I don't think it is as simple as people say, C is the most basic. It doesn't mean that the Foundation is simple. It may be because I didn't learn it well.
C language knowledge Summary
C language Overview
Chapter 1. Overview
1. Basic knowledge of C Language
1.1 C language execution steps
Edit-enter the program code to generate the source program *. c
Compile-syntax analysis error: translation to generate the Target Program *. obj
(Syntax or logic error, starting from the first change, variable definition, statement format, expression format, etc)
Link-assemble with other target programs or libraries to generate executable programs *. exe
Run
1.2 Basic knowledge of the main Function
Location of the main () function
C Programs are always executed from the main () function.
A c program can contain a main function, that is, the main () function. It can also contain a main () function and several other functions.
1.3. c program structure
Functions and main functions
A program consists of one or more functions.
There must be one and only one main function main ()
Program Execution starts from main and ends in main. Other functions can be executed through nested calls.
Program Statement
A c program consists of statements.
Use ";" as the statement Terminator
Note
//
Or
/**/Is a comment and cannot be nested
No compilation code
1.4 c program writing rules
Used to Use lowercase letters, case sensitive
No row number. No program line concept: A statement usually occupies one row.
Empty rows and spaces can be used.
It is commonly used for the writing format of the tooth form; statements of the same hierarchy are aligned up and down.
Chapter 2 Basic Data Types and operations
2.1. Data Type of c program
Note the differences between types and variables (the types are fixed names and variables are their own names)
Storage space occupied by Variables
Data Type
Basic types: integer, complex, and floating point (single precision and Double Precision)
Construction type: array type and struct type
Pointer type
Null type
Note the initial value Assignment Method for the basic type.
Basic Data Type Representation
Integer Data
Decimal: starts with a non-zero number, for example, 123,-9, 0
Octal; starts with 0, for example, 0123,067
Hexadecimal: starting with 0x, for example, 0x123, 0xff
Real Data
Decimal: it must contain a decimal point, for example, 123.0,-9.0.
Exponential form, for example, 1.23E3, 0.9e-2, 5e2
Balanced data
Common characters: for example, 'A', '2', 'h ','#'
Escape characters: for example, '\ n',' \ 100', '\ xlf ,'\\'
(Realize the alignment of several columns: Specify the width. For example, % 100 \ '\ t)
(String Length. "Abc \ n \ t \" strlen 6; sizeof 7)
Storage length of the basic data type
Integer
Int Byte Count 2-digit 16-32768-32767
Short 2 16-32768-32767
Long 4 32-2147483648-2147483647
Real-type
Float 4 32 3.4e-38---3. 4e38
Double 8 64 1.7e-308---1. 7e308
Character Type
Char 1 8-128----127
2.2 identifier naming rules
C-language flag naming rules
An identifier consists of numbers, letters, and underscores.
The identifier must start with a letter or underline.
The identifier cannot be a reserved word (keyword) in C language)
For example, auto extern sizeof float static case for struct char goto switch continue in typedef const if union default long ...... remaining full text>