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 app_code folder in asp net?
What are the Types of session management in ASP.NET
How to deploy/publish webservices?How many ways?Plz explain me
Does asp.net still recognize the global.asa file?
What is a postback ispostback and autopostback in asp net?
What is web router?
Describe the difference between inline and code behind - which is best in?
Explain login control and form authentication.
Can we have multiple web config files for an asp.net application?
What is parse in asp.net?
When maintaining session through sql server, what is the impact of read and write operation on session objects?
What are resource file and how do we generate resource file?
How can we create custom controls in asp net?
Are cookies stored on server or client?
Explain diff between dataset and datareader?