C # experience in using static methods

Source: Internet
Author: User
    The C # static method usage experience mainly introduces some practical problems encountered during the use of the C # static method and the experience of using the C # static method.

     

    C # What are the drawbacks of static methods? In the actual development process, we will notice the impact of the C # static method on our program. What are the experiences of using the C # static method? Here we will look at some aspects:

     

    C # problems encountered when using static methods:

     

    There are almost no static methods in the source code project, but almost all sqlhelper in MS uses static methods. Why? Let's take a look at the following possibilities:

     

    1. In some systems, static methods are used frequently to improve system performance. I think so :)

     

    2. It cannot be upgraded. Rewriting depends on the purpose of a software product.

     

    3. For convenience, you do not need to instantiate the program, but the system resources are occupied during program compilation and running.

     

    4. C # static methods and attributes are all loaded into the memory when the program starts, regardless of whether these methods and attributes are used in the future. Even if no one accesses the program, this part of the memory will not be released. In addition, the data of all the static attributes seen by the visitor is almost the same. For example, if user a sets the username attribute, during User B's access, the username is still the one set by user. If this feature is used in fixed data, there will be no major problems, such as the connection string.

     

    5. C # static methods/data members belong to a class rather than an object, so they do not need to be instantiated. Static methods and static data members are equivalent to shared variables. Because all objects in this class are shared, it is a good choice to define this type when you need to share data. Once a class is defined (it is not necessary to instantiate the object), all the static members of the class are loaded into the memory (not when the program is started, but not when the class is not defined) the scope of a static member is the same as that of its class.

     

    I will introduce you to the usage of the C # static method. I hope it will be helpful for you to learn and use the C # static method.

     

     

     

     

     

     

     

     

     

     

    Reprinted Source: http://developer.51cto.com/art/200908/147734.htm

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.