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 postback request?
How do you secure your connection string information?
What is hidden field in asp.net?
How we implement web farm and web garden concept in asp.net?
How do session tokens work?
Which namespace is used by ado.net?
List some of the important session state modes of asp.net.
What are the advantages and disadvantages of session?
How many types of session state management options available in asp.net?
What is server side session?
How do cookies work? Give an example of their abuse.
How can we make sure that Web API returns JSON data only?
How do u optimize a query in asp.net?
What is difference between web api and web services?
What are Caching techniques in .NET