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

#Intel #Core #i9 #Processors: A Breakdown

Intel Core i9 Processors: A Breakdown Intel's 14th Gen Core i9 series offers a range of processors designed for various use cases. Her...