how to implement singelton in C# & its uses?



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

Post New Answer

More C Sharp Interview Questions

What is a factory in c#?

0 Answers  


How will you get the different language strings?

0 Answers  


Why do we need nullable types in c#?

0 Answers  


How?s method overriding different from overloading?

4 Answers  


What is the difference between ref & out parameters in c#?

0 Answers  


Is datetime a value type in c#?

0 Answers  


What connections does Microsoft SQL Server support?

3 Answers  


How many bits is int32?

0 Answers  


Does the system.exception class have any cool features?

0 Answers  


How do I run managed code in a process?

0 Answers  


Which are the loop types available in c#?

0 Answers  


What are the keywords used to pass parameters to the base class and how do I invoke other constructors.

3 Answers  


Categories