how to implement singelton in C# & its uses?
Answer / 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 |
What is a factory in c#?
How will you get the different language strings?
Why do we need nullable types in c#?
How?s method overriding different from overloading?
What is the difference between ref & out parameters in c#?
Is datetime a value type in c#?
What connections does Microsoft SQL Server support?
How many bits is int32?
Does the system.exception class have any cool features?
How do I run managed code in a process?
Which are the loop types available in c#?
What are the keywords used to pass parameters to the base class and how do I invoke other constructors.