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
Is stringbuilder thread safe c#?
What is thread pooling?
When was .net linq added?
What do you mean by delegates and explain different types of delegates?
what is a structure in c#
In a single .NET DLL how many classes it contains?
What is the difference between double and decimal in c#?
What is the difference between namespace and class?
What is expression tree with example?
What are the 2 kinds of data type conversions in c#?
What is the function of the not null constraint?
Different between method overriding and method overloading?
What is dataadapter c#?
What are the advantages of using delegates in c#?
What is the adv of using System.Text.StringBuilder over System.String?