The example in this paper describes the implementation of the Singleton in C #. Share to everyone for your reference. The implementation method is as follows:
The code is as follows:
#region "To implement a singleton for this window class, the Singleton class is often used for windows that are opened by the main window in the show () method, and only one such object is opened after using the singleton"
1. Privatization of constructors, so that external cannot be new (open heap space, create objects, call constructors)
Private Fstudentman ()
{
InitializeComponent ();
}
2. Create a static variable for a private form class
private static Fstudentman single;
3. Create a static public method to return the form class object
public static Fstudentman Getsingle ()
{
if (single = = null| | Single. isdisposed)
{
Single=new Fstudentman ();
}
return single;
}
#endregion
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
Implementation of single example in C #
This address: http://www.paobuke.com/develop/c-develop/pbk23174.html
Related content C # ways to insert new paragraphs and hidden paragraphs into a Word document C # action SQL Server2008 Interface Instance code C # All operations Method (summary) of the math class in the Microsoft C # Excel Import export support for different versions of Office
Example of using LINQ to XML in a C # program to query XML format data C # Implement a subform with a parent form communication Method Instance Summary C # push information to APNs method C # Simple alarm program implemented with a timer
Implementation of single example in C #