I am very interested in the Design Pattern recently and began to learn terrylee's. Net Design Pattern series. Article : The link below
Http://terrylee.cnblogs.com/archive/2006/06/01/334911.html
[Single-State mode] creates a class. We can only use the same instance of this class.
1 Using System;
2
3 Namespace Classlibrary_ax
4 {
5 Public Sealed Class Singleton
6 {
7 // Create a static Singleton instance, which is not accessible externally (different projects in the same solution)
8 Static Readonly Singleton onlyone = New Singleton ();
9 // Private constructor cannot create instances externally
10 Private Singleton ()
11 {
12}
13 // Returns an onlyone instance through the onlyone attribute of Singleton.
14 Public Static Singleton onlyone
15 {
16 Get
17 {
18ReturnOnlyone;
19}
20 }
21 }
22 }
[Append]
You can set:Public sealed class Singleton
Changed:Public class Singleton
Because: Constructor is marked as private, which cannot be instantiated.
Strictly speaking, it cannot be instantiated outside the class. It can be instantiated inside the class (this method can be used to implement the single-piece design mode ). Note that such classes cannot be inherited as base classes.
Reference: Interface part of epjnpe
Http://epjnpe.cnblogs.com/archive/2006/06/11/423311.html