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 are the Types of object in asp
Describe the diffeerence between inline and code behind?
What’s the catch?
What is inheritance and an how it be used, example with an example?
What are the features of asp net?
Explain one critical mapping?
What is the difference between pathparam and queryparam?
What are client activated objects and server activated objects?
What is a windows service?
What is is post back property in asp net?
What is the difference between typeof() vs gettype()?
If 200 is for all successful operation then why do we have 201 response codes?
What is global.asax file used for?
What is razor? : asp.net mvc
Explain code snippet to register exception filters from controller?