C # High-Performance Code 2

Source: Internet
Author: User

1. The code can be reused as much as possible, but the layers cannot be too many. Otherwise, it is not easy to maintain the code. For example, add a method SaveTestDoDate () that everyone can call (), in other cases, code robustness can be called. Consider some unexpected code. If you want to use an object, you must first determine whether it is empty or whether it exists, that is, anti-stay, in addition, a prompt is provided to avoid any adverse effects caused by changes made by the original party, and to facilitate maintenance and identify errors. For example, js: If you want to obtain an object obj, first determine whether the obj exists. If not, alter the corresponding prompt content, in this step, we seldom do this. If the method for obtaining obj is changed, we can immediately find out the cause. Www.2cto. com3 should not be hard-coded as much as possible, from the database or the enum value, and take the corresponding value in the database or enmu when judging. For example: switch (iocnSkin) {// do not use hard encoding, for example, case 1: // it should be like this case (int) EnmumSkin. folder: in Case 1, it does not indicate a folder but a test case. Therefore, many changes are involved and the code maintenance is inconvenient. If the value of enmu is written, you only need to change the value of enmu elsewhere. Here is an example.

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.