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
Can you inherit multiple classes in c#?
What is asax file in c#?
What is executenonquery c#?
What is different between Static Constructor and Private Constructor?
Explain the ways to deploy an assembly?
List some of the basic string operation?
Is multilevel inheritance possible in c#?
What is cshtml extension?
What is fcl in c#?
What is parallel programming in c#?
What is the difference between integer and double?
Define parsing? Explain how to parse a datetime string?
What is the difference between finalize() and dispose()?
What is the usage of OLE?
What is difference between float and decimal?