WebHosting

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

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...