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 a partial method?
What is the difference between internal and protected in c#?
What is ienumerable <> in c#?
What is hashtable in c# with example?
What is int16?
Explain the steps to create satellite assembly?
What is overriding in c#?
What is a protected class c#?
What is executenonquery c#?
What is the use of table aliases?
Which is executed if an exception has not occurred?
What is multithreading with .net?
How can it prevents DLL Hell assembly versioning in .NET?
Explain the difference between // comments, /* */ comments and /// comments?
From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?