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 the difference between a method and a property?
What are the benefits of using generics?
What is a method signature?
Can a struct inherit from an interface in c#?
Which is faster iqueryable or ienumerable?
What you mean by delegate in c#?
Can a dictionary have the same key?
What is remote data?
Is the following code legal?
What is console readkey in vb net?
Explain About DTS package
What's the difference between WindowsDefaultLocation and WindowsDefaultBounds?
Which program construct must return a value?
Explain about generics in c#.net?
Can abstract class have private constructor c#?