IDesign C # Programming specification (i)

Source: Internet
Author: User
Tags aliases anonymous comments serialization web services
Programming | Specification IDesign released C # Programming specification, chick shooter from Only4gurus Download Browse determined to take time to translate, to better learn.

The contents of the directory are as follows:

1 naming rules and styles naming conventions and style
2 Coding Convention Coding practices
3 Project setup and structure project settings and Structure
4 Framework Special Guidance framework specific guidelines
4.1 Data access
4.2 ASP. NET and Web Service asp.net and web Services
4.3 Serialization of serialization
4.4 Multi-thread multithreading
4.5 Remoting Remoting
4.6 Security
4.7 Service Components Enterprise Services
5 Resource Resources

Today I only translated the naming rules section, the translation and the original text are compared to the following, where the tip is attached,:-)



Naming rules and styles
Naming conventions and Style

1. Class and method names using Pascal style
Use Pascal casing for type and method names
public class SomeClass
{
Public SomeMethod () {}
}
2. Local variables and method parameters adopt camel Style
Use camel casing for local variable names and method arguments
int number;
void MyMethod (int somenumber)
{}
3. Interface name using I as prefix
Prefix Interface name with I
Interface IMyInterface
{..}
4. Private member variable with m_ as prefix
Prefix Private member variables with M_
public class SomeClass
{
private int m_number;
}
5. Custom attribute class name using attribute as suffix
Suffix custom attribute classes with attribute.
6. Custom exception class name using exception as suffix
Suffix Custom exception classes with exception.
7. Use verb-object to name method, such as ShowDialog ()
Name methods using Verb-object pair, such as ShowDialog ()
8. A method with a return value should be named to indicate its return value, such as Getobjectstate ()
Methods with return values should have a name describing the value returned, such as Getobjectstate ().
9. Use descriptive variable names.
Use descriptive variable names.
(a) Avoid the use of single letter variable names, such as I or T, instead of index or temp.
Avoid single character variable names, such as I or T. Use index or temp instead.
(b) Avoid the use of Hungarian nomenclature for public and protected members.
Avoid using Hungarian notation for public or protected members.
c Do not use abbreviations (for example, number abbreviated to NUM).
Do not abbreviate words (such as Num instead of number).
10. Always use C # predefined types, rather than using aliases in the System namespace. For example: Use object without object, use string without string, use int without Int32.
Always use C # predefined types rather than the aliases in the System namespace.
For example:
Object Not Object
String Not string
int not Int32
11. For generics, the type uses uppercase letters. When dealing with. NET type, the suffix type is reserved.
With generics, use the letters for types. The Reserve suffixing type is dealing with the. NET type type.
That's right:
Correct:
public class LinkedList
Avoid using:
Avoid:
public class LinkedList
12. Use a meaningful namespace name, such as a product name or company name.
Use meaningful namespaces such as the product name or the company name.
13. Avoid using the full name of the class, using the using statement instead.
Avoid fully qualified type names. Use the using statement instead.
14. Avoid using using statements within namespaces.
Avoid putting a using statement inside a namespace.
15. Put all the framework namespace names together, followed by a custom or Third-party namespace name.
The Group all framework namespaces together and put the custom or third party namespaces underneath.
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using MyCompany;
Using MyControls;
16. Delegate inference is not an explicit instantiation of a delegate.
Use delegate inference instead of explicit delegate instantiation
delegate void Somedelegate ();
public void SomeMethod ()
{}
Somedelegate somedelegate = SomeMethod;
17. Strictly adhere to the indentation format.
Maintain strict indentation.
A the indentation takes 3 spaces.
Use 3 spaces for indentation.
b Do not use tab or non-standard indentation, such as 1, 2, or 4 spaces.
Do not use tabs or non-standard indentation like 1, 2 or 4 spaces.
18. Annotation indentation and its annotation code at the same level.
Indent comment At the same level of indentation as the code for you are documenting.
19. All annotations are subject to spell checking. Misspelled comments indicate a sloppy development.
All comments should pass spell checking. Misspelled comments indicate sloppy development.
20. All member variables should be defined in the front, and a blank line between the property or method.
All member variables should is declared at the top with one line separating them from the properties or methods.
public class MyClass
{
int m_number;
String M_name;

public void SomeMethod1 ()
{}
public void SomeMethod2 ()
{}
}
21. The definition of a local variable is as close to its initial use as possible.
Declare a variable as close as possible.
22. The filename should reflect the class it contains.
A file name should reflect the class it contains.
23. Each file is named with the type name plus p and ordinal when the partial type is used and each part is assigned a file.
When using partial types and allocating a part of the file, name each file is suffixed with a P and a ordinal nu Mber:
In MyClassP1.cs
public partial class MyClass
{}
In MyClassP2.cs
public partial class MyClass
{}
24. The opening brace is always placed in a new line.
Always Place a open curly brace ({) to New line.
25. Anonymous methods mimic the layout of the normal method, and the anonymous delegate definition is placed on one line.
With anonymous methods mimic the code layout of a regular method, aligned with the anonymous delegate.
(a) Follow the rules for placing left curly braces on new lines.
Comply with placing an open curly brace in a new line
delegate void Somedelegate (string somestring);
That's right
Correct:
public void InvokeMethod ()
{
Somedelegate somedelegate = Delegate (string name)
{
MessageBox.Show (name);
};
Somedelegate ("Juval");
}
Avoid using:
Avoid
public void InvokeMethod ()
{
Somedelegate somedelegate = Delegate (string name) {MessageBox.Show (name);
Somedelegate ("Juval");
}
26. An anonymous method without parameters uses an empty parenthesis.
Use empty parenthesis on parameter-less anonymous methods
A) omits parentheses only if the anonymous method may be used for any delegate.
Omit the parenthesis only if the anonymous is could have been used on any delegate.
delegate void Somedelegate ();
Correct
Somedelegate someDelegate1 = Delegate ()
{
MessageBox.Show ("Hello");
};
Avoid
Somedelegate someDelegate1 = Delegate
{
MessageBox.Show ("Hello");
};

The third


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.