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
How many types of controls are there in asp.net?
Difference between using directive vs using statement?
How do I use response redirect?
Explain about solution explorer window?
What's the difference between viewstate and sessionstate?
What are the server controls in asp.net?
What is event in asp.net?
Explain a program using code nuggets to create a simple application? : asp.net mvc
Where sessions are stored?
Is a dll file an executable?
What does aspcompat="true" mean?
What is the use of global.asax file?
What is sql data source control in asp.net?
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?
What is the concept of postback in asp.net?