50 tips for improving the level of C # programming

Source: Internet
Author: User

an article in the old days, after looking at the feeling can also, especially posted out. 50 key points for improving the level of C # programming:1always use attributes to replace accessible data members2. InReadOnlyAndConstBetween, priority useReadOnly 3. In asand coercion type conversions, precedence is used asoperator4. Use conditional properties (Conditional Attributes) instead of conditional compilation statements#if 5. Always overload the ToString method for a custom class6. Differentiating value types and reference types7. Using immutable value types (immutable Atomic value Types)8. In the value type, make sure that 0 is a valid data9. Understand ReferenceEquals,Staticequals, instance equals and comparison operators (= =) The relationship betweenTenUnderstanding the flaws of the GetHashCode method One. When writing loops, prioritize the use offoreach.  Ato initialize a variable when it is defined. -. Using static constructors to initialize static member variables -when using multiple constructors, use the constructor chain the. Use using and try/finally to handle the release of resources -try to avoid the generation of resource waste. -Avoid packing (boxing) and unpacking (unboxing) as much as possible. -. Implement the Dispose method of a class +Between interfaces and inheritance (inheritance), the interface is used preferentially (Interface)  -. Distinguishing interfaces and overloads (Overrides) +. With a delegate (Delegate) to implement the callback (callback) A. Using Events (Event) to define the external interface atavoid returning references to members inside a class -. Using metadata to control the program -. Prioritize the use of serializable (serilizable) types -implement IComparable and IComparer interfaces for objects that need to be sorted -. Avoid using the ICloneable interface -. Avoid using type conversion operators inOnly when a base class joins a function that has the same name as an existing function in a derived class, you need to use theNewoperator -. Use cls-as much as possiblecompliant to. Try to write a short, simple function +try to write smaller assemblies (assembly) -. Limit the visibility of types (visibility) the. Write a large-grained web API *when using events, precedence inherits base class events instead of recreating an event $Multi-use framework runtime Debugging (Debug, TRACE, EventLog, etc.)Panax Notoginseng. Using the. NET Standard configuration mechanism -. Use and support the data binding capabilities of. NET in the class the. Using the. NET authentication mechanism (Validation) +Choose the Right Collection class (Collection) according to your needs A. Using a DataSet in a custom structure the. Using attributes (Attributes) +do not over-use reflection (Reflection) -. Create a complete, application-specific exception $as much as possible to consider the possible anomalies of the program and make the processing $. Use Interop as little as possible -. Try to use the security Code (safe codes) -. Learn more, use external tools and resources the. Preparing to use C #2.0(I note: C # should be3. 5 or 4.0) -. Learn the ECMA standard

50 tips for improving the level of C # programming

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.