50 tips to help you improve your C # programming skills

Source: Internet
Author: User

50 key points for improving C # Programming

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

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.