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's the c# syntax to catch any possible exception?
Can you inherit multiple interfaces?
What is the difference between continue and break statement?
Can an abstract class have a constructor c#?
How many aware interfaces are there?
Can we assign null value to integer?
Are classes passed by reference in c#?
List down the differences between “dispose” and “finalize” methods in c#.
What is call back method?
What is the best dependency injection c#?
What is the difference between struct and class in c#?
In which way you can convert a value-type to a reference-type?