Implementation of single example in C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.