Singleton implementation in C
- 2020-12-16 06:05:19
- OfStack
This article gives an example of how to implement singletons in C#. Share to everybody for everybody reference. Specific implementation methods are as follows:
#region " Implements a singleton of this window class, often used by the main window show() Method only opens after using the singleton 1 Objects of this class "
//1. Privatize the constructor so that it cannot be externally new( Open heap space , Create the object and call the constructor )
private FStudentMan()
{
InitializeComponent();
}
//2. create 1 Static private form class variables
private static FStudentMan single;
//3. create 1 Three static public methods return a form class object
public static FStudentMan GetSingle()
{
if (single == null||single.IsDisposed)
{
single=new FStudentMan();
}
return single;
}
#endregion
Hopefully this article has helped you with your C# programming.