Friday, January 13, 2012

Implementing Singleton in C#

Singleton class in oops is a facility that provide us an option to define a class to have single instance throughout the program lifetime, it also help us to have a global access point.
How to implement singleton class in c#:

using System;

public class Singlton

{

private static Singleton instance;

private singleton(){}

public static Singleton instance

{

        get

        {

               if(instance ==null)

               {

                    instance =new Singleton();                      

//Checks if the instance has already been created, 

//if yes will return the already created instance else,

                    //will create a new instance of the Singleton Class.

               }

               return instance;

        }

}

}




No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

🌫️ Project Title: "Fog Buster – AI-Powered Visibility Enhancement System"

🔍 Project Vision: To design a device that allows vehicles (cars, trucks) and aircraft (planes, helicopters, drones) to see clearly during f...