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

What is Partial PostBack in ASP.NET?

1090


Is LINQ performance wise better or using sqlcommand?

5163


If you have an application with multiple security levels though secure login and my ASP.NET web appplication is spanned across three web-servers by using round-robbin load balancing. Explain which is the best approach to maintain login-in state for the users?

1125


How can we create a website?

990


witch is the best insistute in sharpoint course.what abt future of share point course.

3532


How to create a db connection at one place/page so that we can use that connection for all pages/forms/windows.what r the steps ned to be performed if question not clear,let me know

1138


What is an assembly? Explain its parts.

1135


What is app_code folder in asp net?

1098


What would be salary for 8+ years of experience in ASP.NET in different metro city in india?

2518


State differences between MVC and WebAPI

1193


Which object wraps the state or data of a user?

1045


What is the difference between mvc (model-view-controller) and mvp (model-view-presenter)? : asp.net mvc

1069


How do I know asp.net mvc version? : Asp.Net MVC

1094


What is difference between Lambda Expression and LINQ in ASP.NET?

1275


Explain difference between friend and protected friend?

970