Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Singleton Design pattern?How do you achieve it?

Answer Posted / sudhir sheoran

Singleton design pattern can be achieved by following implementation:

1) Make class public

2) Static method to generate the instance of class(calling this method we can get the instance of a class if already a instance is generated we will get the same instance)

3) Private Constructor (so that no other class can generate the instance of singleton class)

Example::

class Class1
{
private static Class1 classInstance;
private IList<int> list = new List<int>();
private Class1()
{
if (list == null)
{
list = new List<int>();
}

}

public static void GetInstance()
{
if (classInstance == null)
{
classInstance = new Class1();
}

}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to automatically get the latest version of all the asp.net solution items from source safe when opening the solution?

968


What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?

1023


What are the asp.net list controls and difference between them?

1024


What is data binding in asp net?

1094


What does the orientation property do in a menu control?

994


How we can force all the validation controls to run?

992


Define xmlvalidatingreader class.

1084


Why is global asax is used?

1027


In What Order Do The Events Of An Aspx Page Execute. As A Developer Is It Important To Undertsand These Events?

1025


What is caching? What are different ways of caching in asp.net?

1311


What is preprocessor in .net and type, where it use?

1207


Can I read the hard disk serial # of the client computer using asp.net?

1094


How can we create Tree control in asp.net?

1040


Define static function?

1014


What are the elements of a website?

1002