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 the difference between dispose() and finalize() methods in c#?

1 Answers  


What are the differences between a class and a struct?

1 Answers  


What is extended method in c#

3 Answers   iNautix,


What is the use of dll file in c#?

1 Answers  


What is default parameter in c#?

1 Answers  


What is the Difference between a sub and a function?

3 Answers   Wipro,


what is partial assembly reference

1 Answers  


What is datasource c#?

1 Answers  


Explain the process of abstraction with an example?

1 Answers  


How main method is called in c#?

1 Answers  


What is the use of xmlserializer?

1 Answers  


What?s a multicast delegate?

3 Answers  


Categories