Answer Posted / chandana
To implement a singleton in C#, the steps are:
1. Make the constructor private
2. Declare a static object of the same class
3. Define a static method which return the same object.
This method checks the static variable object, if it
exists, return the same, if it doesn't exist, then creates
a new instance and returns.
This is used when we want to limit the object creation to
only one object for a particular class. e.g., For a
company, we would like to limit the object of type CEO to
be only one. (that means, we know that only 1 CEO exists
for a company).
| Is This Answer Correct ? | 8 Yes | 0 No |
Post New Answer View All Answers
What is signature c#?
What is a generic c#?
What is ilist c#?
Define interface class in c#?
Describe a Struct ?
What is the delegate in c#?
What are the different types of assemblies available and their purpose?
What Is The Difference Between The System.array.copyto() And System.array.clone()?
Why do we need serialization?
Can you inherit multiple abstract classes in c#?
What is difference between function and method in c#?
What basic steps are needed to display a simple report in crystal?
What is array collection?
Explain concurrency with aop?
How do you mark a method obsolete?