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 jagged array?
What is .cshtml file?
What is difference between abstract class and interface in c#?
What is the difference between Singleton design pattern and Factory design pattern?
What are the basics of c#?
What is callback method in c#?
What are functions in c#?
What is interface c#?
What are partial classes and use of partial classes?
Can you explain template pattern?
What is the use of console readline () in c#?
Why dictionary is used in c#?
What is the relationship between a process, application domain, and application?
What do multicast delegates mean?
Explain About disco and uddi