Singleton mode definition:A class has only one instance and is self-instantiated to provide to the entire system.
Implementation points:
1. The Singleton mode class only provides private constructors.
2. The class definition contains a static private object of the class.
3. This class provides a static common function for creating or obtaining its own static private object.
Dual lock implementation code (within multiple threads ):
Namespace Singleton {public class Singleton {// defines a Private Static global variable to save the Private Static Singleton _ Singleton; // define a read-only static object // and the object is the Private Static readonly object _ lockobj = new object () created when the program runs (); /// <summary> /// the constructor must be private. // you cannot use new to create a private Singleton () {}/// <summary> /// define a global access point // set it to a static method // This method can be called without instantiation outside the class/ /// </Summary> /// <returns> </returns> Public static Singleton getinstance () {// here we can ensure that the instance is instantiated only once // that is, the instance is instantiated at the first call // the call will not be instantiated later // The first Singleton = NULL if (_ Singleton = NULL) {lock (_ lockobj) {// Singleton = NULL if (_ Singleton = NULL) {_ Singleton = new Singleton ();}}} return _ Singleton ;}}}