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
What is Partial PostBack in ASP.NET?
Is LINQ performance wise better or using sqlcommand?
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?
How can we create a website?
witch is the best insistute in sharpoint course.what abt future of share point course.
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
What is an assembly? Explain its parts.
What is app_code folder in asp net?
What would be salary for 8+ years of experience in ASP.NET in different metro city in india?
State differences between MVC and WebAPI
Which object wraps the state or data of a user?
What is the difference between mvc (model-view-controller) and mvp (model-view-presenter)? : asp.net mvc
How do I know asp.net mvc version? : Asp.Net MVC
What is difference between Lambda Expression and LINQ in ASP.NET?
Explain difference between friend and protected friend?