50 key points for improving C # Programming

Source: Internet
Author: User

1. attribute is always used to replace accessible data members.
2. readonly and const are preferred.
3. The as operator is preferred between as and forced type conversion.
4. Use the Conditional attribute (Conditional Attributes) to replace the Conditional compilation statement # if
5. Always reload the ToString method for the custom class
6. Differences between value types and reference types
7. Immutable Atomic Value Types)
8. In the value type, make sure that 0 is a valid data.
9. Understand the relationship between ReferenceEquals, static Equals, instance Equals and comparison operators (=)
10. Understand the defects of the GetHashCode Method
11. foreach is preferred when writing loops.
12. initialize the variable when defining it.
13. Use a static constructor to initialize static member variables
14. When multiple constructor functions are used, the constructor chain is used.
15. Use using and try/finally to release resources.
16. Avoid resource spam as much as possible
17. Avoid using boxing or unboxing)
18. Implement the Dispose method of the class
19. The interface is preferred between the interface and the Inheritance (Inheritance)
20. differentiate between interfaces and overloads)
21. Use a delegate to call back)
22. Use events to define External Interfaces
23. Avoid returning references from class members.
24. use metadata to control programs
25. The serializable type is preferentially used.
26. Implement IComparable and IComparer interfaces for objects to be sorted
27. Avoid using the ICloneable Interface
28. Avoid using the type conversion Operator
29. The new operator is required only when the base class has the same name as the existing function in the derived class.
30. Try to use CLS-Compliant
31. Try to write short and simple functions
32. Try to write a smaller assembly)
33. Define type visibility (visibility)
34. Compile a large-granularity web API
35. When using events, the base-class events are inherited first, instead of re-creating an event.
36. DEBUG (DEBUG, TRACE, EVENTLOG, etc.) when using the framework)

37. Use the. net standard configuration mechanism 38. Use and support the. net Data Binding function in the class)
39. Use the. net authentication mechanism (Validation)
40. Select the correct Collection class based on your needs)
41. Use DataSet in the Custom Structure
42. Attributes)
43. Do not over-use Reflection (Reflection)
44. Create a complete application-specific exception
45. Consider as many exceptions as possible and handle them.
46. Use Interop as few as possible
47. Try to use safe code)
48. Learn more and use external tools and resources
49. Prepare to use C #2.0.
50. Learn ECMA standards

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.