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
Value Type and Reference Type Data type in C#?
What does public mean in c#?
Why do canadians say zed?
Why do we need nullable types in c#?
Why do we use abstraction in c#?
What is the difference between “out” and “ref” parameters in c#?
What is the difference between delegates and events in c#?
What is xml document how do you open it?
To allow an element to be accessed using a unique key which .NET collection class is used ?
Why do we need delegates in c#?
Why delegates are type safe?
What is a scope in c#?
what are windows services?
How can we sort the elements of the array in descending order?
What is meant by enumerable in c#?