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 many types of controls are there in asp.net?

961


Difference between using directive vs using statement?

937


How do I use response redirect?

932


Explain about solution explorer window?

991


What's the difference between viewstate and sessionstate?

998


What are the server controls in asp.net?

910


What is event in asp.net?

964


Explain a program using code nuggets to create a simple application? : asp.net mvc

974


Where sessions are stored?

1053


Is a dll file an executable?

981


What does aspcompat="true" mean?

979


What is the use of global.asax file?

989


What is sql data source control in asp.net?

1009


Am not able to move the controls on the form freely in asp.net 3.5 even though I selected the position as relative or absolute for those controls. What should I do to overcome this?

2326


What is the concept of postback in asp.net?

1000