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