. net4.0 design mode (i) Single-case mode with lazy

Source: Internet
Author: User

Deferred loading, also known as deferred instantiation, delayed initialization, etc.

The main idea is that the creation of the object will be deferred to the time it was created, rather than the object being created when the object was instantiated, that is, when it is loaded. This approach helps to improve application performance, avoid wasted computing, save memory usage, and more. For this approach, it seems that it is more appropriate to create a "ready to use".

. NET Framework4.0 provides a wrapper class Lazy<t>, which makes it easy to implement lazy loading.

 Public classlazysingleton{//privatization constructor for Singleton modePrivateLazysingleton () {}//Lazy prototype for lazy<t> object name =new lazy<t> (fun<t>)    Private Static ReadOnlyLazy<lazysingleton> linstance =NewLazy<lazysingleton> (() = {return NewLazysingleton ();});//gets the value of the current object through the Value property.      Public StaticLazysingleton Instance {Get{returnLinstance.value;} }//you can determine whether an object has been created by using the IsValueCreated property     Public Static BOOLisvaluecreated {Get{returnlinstance.isvaluecreated;} }}

. net4.0 design mode (i) Single-case mode with lazy

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.