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

Explain what are three test cases you should go through in unit testing?

0 Answers  


Why delegates are type safe?

0 Answers  


What are the applications of c#?

0 Answers  


FOR EXAMPLE : CLASS Dotnet { } creating object: Dotnet dn=new Dotnet(); NOW THE QUESTION IS WHICH IS CALLED AS OBJECT ? EITHER dn OR new Dotnet() and CAN YOU PROVE YOUR ANSWER????? PLEASE REPLY...

2 Answers  


What is sqlcommandbuilder c#?

0 Answers  






What is the system namespace?

0 Answers  


Can delegates be used as callbacks?

0 Answers  


What are handlers in c#?

0 Answers  


Why do we use void in c#?

0 Answers  


What is dynamic dispatch?

0 Answers  


what is an internal specifier? what happens internally when I use access specifier Internal ?

4 Answers   rsystems,


Please explain value types and reference types used in c#?

0 Answers  


Categories